数据类型
- int, 整数类型
- bool, 字符串类型
- str, 字符串类型
- list, 列表类型
- tuple, 元组类型
- dict, 字典类型
- set, 集合类型
- float, 浮点类型
1. int 整数类型
1.1 定义
1.2 独有功能
v1 = 5
res = v1.bit
res = v1.bit_length()
1.3 公共功能
加减乘除
1.4 相互转换
n1 = int(True)
n2 = int(False)
print(int("0b11", base=2))
print(int("123", base=10))
v1 = int(7.4)
1.5 其他
v1 = 9/2
print(v1)
v1 = 9/2
print(v1)
from __future__ import division
v1 = 9/2
print(v1)
2. 布尔类型
2.1 定义
2.2 独有功能
2.3 独有功能
2.4 公共功能
2.5 转换
bool(int)
boot(str)
bool([])
bool({})
2.6 其他
if 1 > 2:
print("666")
else:
print("888")
3. 字符串类型
3.1 独有功能
'xxxx'.功能(....)
v1 = "aadsadsaf"
res = v1.startswith("aa")
print(res)
v1 = "aadsadsaf"
res = v1.endswith("f")
print(res)
v1 = "111"
if v1.isdecimal():
print("这个字符串是数字")
else:
print("这个字符串不是数字")
res = " tttj "
print(res.strip())
res = " tttj "
print(res.strip())
res = "qwert"
print(res.strip("q"))
v1 = "qwert"
print(v1.upper())
v1 = "qWert"
print(v1.replace("q","t"))
v1 = "dsa dsa fds fdewq fes"
print(v1.split(" "))
print(v1.split(" ",2))
print(v1.rsplit(" ",2))
data_list = ["weq", "deadsa", "dsadfsa"]
v1 = "_".join(data_list)
print(v1)
.format和%s
data = "总"
print(data.encode("utf-8"))
v1 = "dsadsa"
print(v1.center(21,"*"))
print(v1.ljust(21,"*"))
print(v1.rjust(21,"*"))
data = "ewqr"
print(data.zfill(10))
3.2 公共功能
'''
1. 相加: 字符串 + 字符串
2. 相乘 3 * 字符串
'''
data = "dsads"
value = len(data)
msg = "dsadsadsaf"
print(msg[0])
print([-1])
msg = "python"
print(message[0:2])
print([3:])
print([2:-1])
print([2:len(msg)])
msg = "python"
print(msg=[ 0:5:2 ])
print(msg=[4:1:-1])
msg = "生活不是电影,生活比电影苦"
index = 0
while index < len(msg):
print(msg[index])
index += 1
for k,v in enumerate(msg):
print(k,v)
3.1 定义
3.1 定义
|