【小白学 Python3】04 – 变量与字符串

变量与字符串

知识点

  • 变量的定义
  • 字符串的基本使用

实战演习

test.py

# 数字变量
a = 1
b = 2
print(a+b)

# 字符变量
s1 = "helo"
s2 = "koma"
print(s1 + s2)  #
print(s1, s2)
print(s1,s2,s2,s1)  #可以多次扩展


输出:

helokoma
helo koma           # 可以很好区分内容
helo koma koma helo

# 字符函数
msg = "HELO world!"
print(msg)
print(msg.title())   #首字母大写
print(msg.upper())   #全大写
print(msg.lower())   #全小写

输出:
HELO world!
Helo World!
HELO WORLD!
helo world!

# 转义字符
msg = "I can:\n\tPython\n\tJavascript"  #换行\n,一个tab键
print(msg)

输出:
I can:
        Python
        Javascript

# 删除余白
msg = " Curry is MVP. "
print("|" + msg + "|")
print("|" + msg.rstrip() + "|")  #右边删除right
print("|" + msg.lstrip() + "|")  #左边删除left
print("|" + msg.strip() + "|")

输出:
| Curry is MVP. |
| Curry is MVP.|
|Curry is MVP. |
|Curry is MVP.|

课程文件

https://gitee.com/komavideo/LearnPython3

小马视频频道

http://komavideo.com

暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇