变量与字符串
知识点
- 变量的定义
- 字符串的基本使用
实战演习
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