1.计数器enumerate
date_list = [11,22,33,44,55]
for i,item in enumerate(date_list,1):
print(i,item)
2.条件判断if
a = 1
if a =1:
print("成功")
3.判断包含in
a = "存在先于本质"
if a in ["存在先于本质","祸兮福所倚"]:
print("包含")
4.否,不not
a = "存在先于本质"
if a not in ["a","b","c"]:
print("不包含")
5.抓取器for…in…
a = [1,2,3,4,5,6,7,8,9]
for b in a:
print(b)
6.abs 绝对值
v = abs(-10)
7.pow 指数
v1 = pow(2,5) # 2的5次方 2**5
print(v1)
8.sem 求和
v1 = sum([-11, 22, 33, 44, 55]) # 可以被迭代-for循环
print(v1)
9.divmod 求商和余数
v1, v2 = divmod(9, 2)
print(v1, v2)
10.round 浮点类型数据取小数点后的位置
v1 = round(4.11786, 2)
print(v1) # 4.12
11.min 最小值
v1 = min(11, 2, 3, 4, 5, 56)
print(v1) # 2
12.max 最大值
v1 = max(11, 2, 3, 4, 5, 56)
print(v1)
13.all 是否全部为True
v1 = all( [11,22,44,""] )
14.any 是否存在True
v2 = any([11,22,44,""])
15.bin 十进制转二进制
print(bin(11))
16.oct 十进制转八进制
print(oct(11))
17.hex 十进制转十六进制
print(hex(11))
18.ord 获取字符对应的unicode码点(十进制)
v1 = ord("武")
print(v1, hex(v1))
19.chr 根据码点(十进制)获取对应字符
v1 = chr(27494)
print(v1)
20.int 整型
print(int("11")>1)
21.float 浮点类型
print(float("11.11")>1)
22.str 字符串类型unicode编码
print(type(str("11"))==str)
23.bytes 字节类型utf-8、gbk编码
v1 = "武沛齐" # str类型
v2 = v1.encode('utf-8') # bytes类型
v3 = bytes(v1,encoding="utf-8") # bytes类型
24.bool 布尔类型
print(bool(1))
25.list 列表类型
print(list("存在先于本质"))
26.dict 词典类型
a = { }
print(type(a) == dict)
27.tuple 元组类型
a = (1,)
print(type(a) == yuple)
28.set 集合类型
a = set()
print(type(a) == set)
29.len 获取字符串长度
print(len("存在先于本质"))
30.print 输出
print("存在先于本质")
31.input 输入
a = input("请输入")
print(a)
32.open 打开文件
with open("1.txt", mode = "r+", encoding = "utf-8") as a:
a.write("啊吧啊吧")
33.type 获取数据类型
v1 = "123"
if type(v1) == str:
print("是字符串类型")
else:
print("不是字符串类型")
34.range 数字生成器
range(10)
35.id 查看内存地址
a = 1
id(a)
36.hash 哈希
v1 = hash("武沛齐")
37.help 帮助信息,一般在终端使用
help(str)
38.zip 将不同的列表元素根据索引挨个关联成一个元组
v1 = [11, 22, 33, 44, 55, 66]
v2 = [55, 66, 77, 88]
v3 = [10, 20, 30, 40, 50]
result = zip(v1, v2, v3)
for item in result:
print(item)
39.callable 检查是否是可执行
v1 = "武沛齐"
v2 = lambda x: x
def v3():
pass
print( callable(v1) ) # False
print(callable(v2))
print(callable(v3))
40.sorted 排序
v1 = sorted([11,22,33,44,55])