一 、变量与字符串
1、数字变量
a = 1
b = 2
print(a+b)
——————————————————————————————————————————————————————————
a = 1
b = 2
print(a+b)
print(a-b)
print(a*b) #(*乘)
print(a/b) #(/除)
输出结果


2、字符变量
s1 = "hello"
s2 = "python"
print(s1+s2) #(+拼接字符)
print(s1, s2) #(,输入字符串中间加空格)ps:方便简单
print(s1, s2, s1, s2)
输出结果

3、字符函数
M_n = "HELLO python"
print(M_n) #(原模原样打印出来)
print(M_n.title()) #( title() 首字母大写)
print(M_n.upper()) #( upper() 全大写)
print(M_n.lower()) #( lower() 全小写)
输出结果

4、转义字符串
Me = "\n\t山不在高,有仙则名。\n\t水不在深,有龙则灵。\n\t南阳诸葛庐,西蜀子云亭。"
print(Me)
#(\n 代表回车)
#(\t 代表Tab位)
输出结果

5、删除余白(常用)
Me = " 山不在 高 有仙则名. "
print("|" + Me + "|")
print("|" + Me.rstrip() + "|") # rstrip() 去掉右边的空白
print("|" + Me.lstrip() + "|") # lstrip() 去掉左边的空白
print("|" + Me.strip() + "|") # strip() 同时去掉左右空白
输出结果


浙公网安备 33010602011771号