基本数据类型-列表_元组_字典
一、列表(list)书写格式:[]
1 #通过list类创建的 2 3 li = [1, 12, 9, "age", ["刘正文", ["19", 10, ],"庞麦郎"], "ales", True]
1、列表格式2、列表中可以嵌套任何类型
- 中括号起来
- ,分割每个元素
- 列表中的元素可以是 数字,字符串,列表,布尔值....所有的都能放进去
- "集合" ,内部放置任何东西
3、索引取值
1 li = [1, 12, 9, "age", ["刘正文", ["19", 10, ],"庞麦郎"], "ales", True] 2 print(li[3]) #索引取值
执行结果:
1 age
4、切片,切片结果也是列表
1 li = [1, 12, 9, "age", ["刘正文", ["19", 10, ],"庞麦郎"], "ales", True] 2 print(li[3:-1]) #切片,切片的结果也是列表
执行结果:
1 [‘age‘, [‘刘正文‘, [‘19‘, 10], ‘庞麦郎‘], ‘ales‘]
5、for循环
while循环
1 li = [1, 12, 9, "age", ["刘正文", ["19", 10, ],"庞麦郎"], "ales", True] 2 for item in li: 3 print(item)
执行结果:
1 1 2 12 3 9 4 age 5 [‘刘正文‘, [‘19‘, 10], ‘庞麦郎‘] 6 ales 7 True
6、索引
- 修改
列表元素,可以被修改
ps1:
1 li = [1, 12, 9, "age", ["刘正文", ["19", 10, ],"庞麦郎"], "ales", True] 2 li[1] = 120 3 print(li)
执行结果:
1 [1, 120, 9, ‘age‘, [‘刘正文‘, [‘19‘, 10], ‘庞麦郎‘], ‘ales‘, True]
ps2:
1 li = [1, 12, 9, "age", ["刘正文", ["19", 10, ],"庞麦郎"], "ales", True] 2 li[1] = [11,22,33,44] 3 print(li)
执行结果:
1 [1, [11, 22, 33, 44], 9, ‘age‘, [‘刘正文‘, [‘19‘, 10], ‘庞麦郎‘], ‘ales‘, True]
- 删除
删除,第一种方式
1 li = [1, 12, 9, "age", ["刘正文", ["19", 10, ],"庞麦郎"], "ales", True] 2 del li[1] #删除12 3 print(li)
执行结果:
1 [1, 9, ‘age‘, [‘刘正文‘, [‘19‘, 10], ‘庞麦郎‘], ‘ales‘, True]
7、切片
- 修改
1 li = [1, 12, 9, "age", ["刘正文", ["19", 10, ],"庞麦郎"], "ales", True] 2 li[1:3] = [120,90] #修改12,9 3 print(li)
执行结果:
1 [1, 120, 90, ‘age‘, [‘刘正文‘, [‘19‘, 10], ‘庞麦郎‘], ‘ales‘, True]
- 删除
1 li = [1, 12, 9, "age", ["刘正文", ["19", 10, ],"庞麦郎"], "ales", True] 2 del li[2:6] 3 print(li)
执行结果:
1 [1, 12, True]
8、in操作
作用:判断这个元素是否在列表中
ps1:
值存在这个列表中,就是Ture
1 li = [1, 12, 9, "age", ["刘正文", ["19", 10, ],"庞麦郎"], "ales", True] 2 v = 1 in li #1在这个列表中,就是True 3 print(v)
1 True
ps2:
值不存在这个列表中,就是Flase
1 li = [1, 12, 9, "age", ["刘正文", ["19", 10, ],"庞麦郎"], "ales", True] 2 v = 120 in li 3 print(v)
执行结果:
1 False
ps3:
因为在列表中的元素,以逗号做为分割,就是个整体,所以是Flase
1 li = [1, 12, 9, "age", ["史正文", ["19", 10, ],"庞麦郎"], "ales", True] 2 #因为在列表中的元素,以逗号做为分割,就是个整体,所以是Flase 3 v = "刘正文" in li #史正文在第4个素引的列表中,所以是Flase 4 print(v)
执行结果:
1 False
9、操作
1 li = [1, 12, 9, "age", ["石振文", ["19", 10], "庞麦郎"], "alex", True] 2 li[4][1][0][1] #索引取值,可以一直往里面找
补充知识:
只要我想把某个值,转成什么,就写上对应的类型,就可以进行转换
1 把字符串转成整型 2 3 a = "123" 4 int(a) 5 a = 123
1 把整型转到字符串 2 3 a = 123 4 str(a)
10、转换
1、字符串转换列表 li = list("asdfasdfasdf"), 内部使用for循环
1 s = "pouaskdfauspdfiajsdkfj" 2 new_li = list(s) 3 print(new_li)
执行结果:
1 [‘p‘, ‘o‘, ‘u‘, ‘a‘, ‘s‘, ‘k‘, ‘d‘, ‘f‘, ‘a‘, ‘u‘, ‘s‘, ‘p‘, ‘d‘, ‘f‘, ‘i‘, ‘a‘, ‘j‘, ‘s‘, ‘d‘, ‘k‘, ‘f‘, ‘j‘]
2、列表转换成字符串
需要自己写for循环一个一个处理,即有数字又有符串
1 li = [11,22,33,"123","alex"] 2 r = str(li) # 指的就是把上面列表打印出来 3 print(r)
执行结果:
1 [11, 22, 33, ‘123‘, ‘alex‘]
列表转换成字符串
1 li = [11,22,33,"123","alex"] 2 s = "" 3 for i in li: 4 s = s + str(i) 5 print(s)
执行结果:
1 112233123alex
3、直接使用字符串join方法:列表中的元素只有字符串
1 li = ["123","alex"] 2 v = "".join(li) 3 print(v)
执行结果:
1 123alex
4、补充:
1、字符串创建后,不可修改 replace:替换
1 v = "alex" 2 v = v.replace(‘l‘,‘el‘) 3 print(v)
执行结果:
1 aelex
2、列表
li = [11,22,33,44] li[0] li[0] = 999 s = "alex" li[0] s[0] = "E" li = [11,22,33,44] print(li) print(li) print(li) print(li) print(li) print(li) print(li) print(li) 列表,有序;元素可以被修改 列表 list li = [111,22,33,44]
列表内容的总结:
1. 书写格式 tu = (111,"alex",(11,22),[(33,44)],True,33,44,) 一般写元组的时候,推荐在最后加入 , 元素不可被修改,不能被增加或者删除 2. 索引 v = tu[0] print(v) 3. 切片 v = tu[0:2] print(v) 4. 可以被for循环,可迭代对象 for item in tu: print(item) 5. 转换 s = "asdfasdf0" li = ["asdf","asdfasdf"] tu = ("asdf","asdf") v = tuple(s) print(v) v = tuple(li) print(v) v = list(tu) print(v) v = "_".join(tu) print(v) li = ["asdf","asdfasdf"] li.extend((11,22,33,)) print(li) 6.元组的一级元素不可修改/删除/增加 tu = (111,"alex",(11,22),[(33,44)],True,33,44,) 元组,有序 v = tu[3][0][0] print(v) v=tu[3] print(v) tu[3][0] = 567 print(tu)
二、参数
1、追加 append
1 li = [11, 22, 33, 22, 44] 2 li.append(5) 3 li.append("alex") 4 li.append([1234,2323]) 5 print(li)
执行结果:
1 [11, 22, 33, 22, 44, 5, ‘alex‘, [1234, 2323]]
2、清空列表 clear
1 li = [11, 22, 33, 22, 44] 2 li.clear() #清空列表中的值 3 print(li)
执行结果:
1 []
3、拷贝,浅拷贝 copy()
1 li = [11, 22, 33, 22, 44] 2 v = li.copy() 3 print(v) 4 print(li)
执行结果:
1 [11, 22, 33, 22, 44] 2 [11, 22, 33, 22, 44]
4、计算元素出现的次数 count
1 li = [11, 22, 33, 22, 44] 2 v = li.count(22) #统计22出现了几次,所以是2次 3 print(v)
执行结果:
2
5、扩展原列表,参数,可迭代对象 extend
1 li = [11, 22, 33, 22, 44] 2 li.extend([9898,"不得了"]) 3 print(li)
执行结果:
1 [11, 22, 33, 22, 44, 9898, ‘不得了‘]
6、根据值获取当前值索引位置(左边优先) index
1 li = [11, 22, 33, 22, 44] 2 v = li.index(22) #从0开始数 3 print(v)
执行结果:
1 1
7、在指定索引位置插入元素 insert
1 li = [11, 22, 33, 22, 44] 2 li.insert(0,99) 3 print(li)
执行结果:
1 [99, 11, 22, 33, 22, 44]
8、删除某个值 pop
1.指定索引
2、默认最后一个,并获取删除的值
ps1:
1 li = [11, 22, 33, 22, 44] 2 v = li.pop() 3 print(li) 4 print(v)
执行结果:
1 [11, 22, 33, 22] #删除了44 2 44 #获取删除的值
ps2:
1 li = [11, 22, 33, 22, 44] 2 v = li.pop(1) #指定删除的参数,删除第1个,从0开始数 3 print(li) 4 print(v)
执行结果:
1 [11, 33, 22, 44] 2 22
9、删除列表中的指定值,左边优先 remove
PS:删除的命令一共有几个 pop、remove、del li[0]、del li[7:9]、clear
1 li = [11, 22, 33, 22, 44] 2 li.remove(22) 3 print(li)
执行结果:
1 [11, 33, 22, 44]
10、将当前列表进行翻转 reverse
1 li = [11, 22, 33, 22, 44] 2 li.reverse() 3 print(li)
执行结果:
1 [44, 22, 33, 22, 11]
11、列表的排序(从大到小) sort(reverse=True)
1 li = [11, 22, 33, 22, 44] 2 li.sort() 3 li.sort(reverse=True) 4 print(li)
执行结果:
1 [44, 33, 22, 22, 11]
12、enumrate
为一个可迭代的对象添加序号,可迭代的对象你可以理解成能用for循环的就是可迭代的。默认是编号是从0开始,可以设置从1开始
1 li = ["手机", "电脑", "鼠标垫", "游艇"] 2 for k, i in enumerate(li,1): 3 print(k,i)
执行结果
1 1 手机 2 2 电脑 3 3 鼠标垫 4 4 游艇
三、元组
书写格式:()
1、元组的一级元素不可修改/删除/增加
ps1:
1 tu = (111, "alex", (11, 22), [(33, 44),9], True, 33, 44,) 2 #元组,有序 3 v = tu[3][0][0] 4 print(v)
执行结果:
1 33
ps2:
1 tu = (111, "alex", (11, 22), [(33, 44),9], True, 33, 44,) 2 v = tu[3] #从0开始数, " " () [] 都只能算一个数 3 print(v)
执行结果:
1 [(33, 44), 9]
ps3:
列表可以被替换
1 tu = (111, "alex", (11, 22), [(33, 44)], True, 33, 44,) 2 tu[3][0] = 567 #获取到,列表可以被替换 3 print(tu)
执行结果:
1 (111, ‘alex‘, (11, 22), [567], True, 33, 44)
2、列表和元组的使用说明:
1 什么时候用列表,什么时候用元组 2 可以被修改的就用list 3 不能被修改的就用元组 4 元组要修改的话,可以转成列表,再替换
四、字典(dict)
字典{},列表[], 元组()
总结:
1、字典是以键值对的方式出现:key:value
2、字典的value的值可以是任何值
3、布尔值、列表、字典不能作为字典的key,但元组可以,做为列表的key
4、字典是无序的
书写格式:{}
1、基本结构,字典是以键值对的方式出现
info = { "k1":"v1", #键值对 "k2":"v2" }
“k1”:"v1" 表示为:key:value 前面是key,后面是值
2、字典的value(值)可以是任何值
1 info = { 2 "k1": 18, 3 "k2": True, 4 "k3": [ 5 11, 6 [], 7 (), 8 22, 9 33, 10 { 11 ‘kk1‘: ‘vv1‘, 12 ‘kk2‘: ‘vv2‘, 13 ‘kk3‘: (11, 22), 14 } 15 ], 16 "k4": (11, 22, 33, 44) 17 } 18 print(info)
执行结果:
1 {‘k3‘: [11, [], (), 22, 33, {‘kk1‘: ‘vv1‘, ‘kk2‘: ‘vv2‘, ‘kk3‘: (11, 22)}], ‘k4‘: (11, 22, 33, 44), ‘k1‘: 18, ‘k2‘: True}
3、布尔值、列表、字典不能作为字典的key
ps1:
1 info ={ 2 1: ‘asdf‘, 3 "k1": ‘asdf‘, 4 True: "123", #布尔值不能作为字典的key,只能是值 5 } 6 print(info)
执行结果:
1 {1: ‘123‘, ‘k1‘: ‘asdf‘}
ps2:
1 info = { 2 1: ‘asdf‘, 3 "k1": ‘asdf‘, 4 True: "123", 5 #[11,22]: 123 #列表不能做为字典的key,会报错。 6 (11,22): 123, #元组可以,做为列表的key 7 #{‘k1‘:‘v1‘}: 123 #字典不可以做为字典的key("TypeError: unhashable type:‘dict‘) 8 9 } 10 print(info)
执行结果:
1 {1: ‘123‘, ‘k1‘: ‘asdf‘, (11, 22): 123}
4、字典无序
1 info = { 2 "k1": 18, 3 "k2": True, 4 "k3": [ 5 11, 6 [], 7 (), 8 22, 9 33, 10 { 11 ‘kk1‘: ‘vv1‘, 12 ‘kk2‘: ‘vv2‘, 13 ‘kk3‘: (11, 22), 14 } 15 ], 16 "k4": (11, 22, 33, 44) 17 } 18 print(info)
执行结果:
两次结果进行比较,会发现字典是无序的。
运行程序1次得出的结果:
1 {‘k3‘: [11, [], (), 22, 33, {‘kk1‘: ‘vv1‘, ‘kk3‘: (11, 22), ‘kk2‘: ‘vv2‘}], ‘k1‘: 18, ‘k2‘: True, ‘k4‘: (11, 22, 33, 44)}
再运行程序得出的结果:
1 {‘k4‘: (11, 22, 33, 44), ‘k3‘: [11, [], (), 22, 33, {‘kk1‘: ‘vv1‘, ‘kk3‘: (11, 22), ‘kk2‘: ‘vv2‘}], ‘k1‘: 18, ‘k2‘: True}
5、索引方式找到指定元素
ps1:
取18的值
1 info = { 2 "k1": 18, 3 2: True, 4 "k3": [ 5 11, 6 [], 7 (), 8 22, 9 33, 10 { 11 ‘kk1‘: ‘vv1‘, 12 ‘kk2‘: ‘vv2‘, 13 ‘kk3‘: (11,22), 14 } 15 ], 16 "k4": (11,22,33,44) 17 } 18 v = info[‘k1‘] #获取key的值,就是18 19 print(v) 20 v = info[2] #获取2的值,就是True 21 print(v)
执行结果:
1 18 2 True
ps2:
找到11
1 info = { 2 "k1": 18, 3 2: True, 4 "k3": [ 5 11, 6 [], 7 (), 8 22, 9 33, 10 { 11 ‘kk1‘: ‘vv1‘, 12 ‘kk2‘: ‘vv2‘, 13 ‘kk3‘: (11,22), #找到11 14 } 15 ], 16 "k4": (11,22,33,44) 17 } 18 v = info[‘k3‘][5][‘kk3‘][0] #找到11; 最后元组拿到第一个元素,加[0] 19 print(v)
执行结果:
1 11
6、字典支持 del 删除
ps1:
1 info = { 2 "k1": 18, 3 2: True, 4 "k3": [ 5 11, 6 [], 7 (), 8 22, 9 33, 10 { 11 ‘kk1‘: ‘vv1‘, 12 ‘kk2‘: ‘vv2‘, 13 ‘kk3‘: (11,22), 14 } 15 ], 16 "k4": (11,22,33,44) 17 } 18 del info[‘k1‘]
执行结果:
#删除掉了,所以什么都没有
ps2:
删除kk1
1 info = { 2 "k1": 18, 3 2: True, 4 "k3": [ 5 11, 6 [], 7 (), 8 22, 9 33, 10 { 11 ‘kk1‘: ‘vv1‘, 12 ‘kk2‘: ‘vv2‘, 13 ‘kk3‘: (11,22), 14 } 15 ], 16 "k4": (11,22,33,44) 17 } 18 del info[‘k3‘][5][‘kk1‘] #删除‘kk1‘: ‘vv1‘,
19 print(info)
执行结果:
1 {‘k1‘: 18, ‘k3‘: [11, [], (), 22, 33, {‘kk2‘: ‘vv2‘, ‘kk3‘: (11, 22)}], 2: True, ‘k4‘: (11, 22, 33, 44)}
7、字典的for循环
ps1:
1 info = { 2 "k1": 18, 3 2: True, 4 "k3": [ 5 11, 6 [], 7 (), 8 22, 9 33, 10 { 11 ‘kk1‘: ‘vv1‘, 12 ‘kk2‘: ‘vv2‘, 13 ‘kk3‘: (11,22), 14 } 15 ], 16 "k4": (11,22,33,44) 17 } 18 for item in info: 19 print(item)
执行结果:
1 {2: True, ‘k4‘: (11, 22, 33, 44), ‘k3‘: [11, [], (), 22, 33, {‘kk2‘: ‘vv2‘, ‘kk3‘: (11, 22)}], ‘k1‘: 18} 2 2 3 k4 4 k3 5 k1
ps2:
dict里面的功能
info.keys() 默认循环他所有的key
1 info = { 2 "k1": 18, 3 2: True, 4 "k3": [ 5 11, 6 [], 7 (), 8 22, 9 33, 10 { 11 ‘kk1‘: ‘vv1‘, 12 ‘kk2‘: ‘vv2‘, 13 ‘kk3‘: (11,22), 14 } 15 ], 16 "k4": (11,22,33,44) 17 } 18 for item in info.keys(): 19 print(item)
执行结果:
1 {‘k4‘: (11, 22, 33, 44), 2: True, ‘k3‘: [11, [], (), 22, 33, {‘kk3‘: (11, 22), ‘kk2‘: ‘vv2‘}], ‘k1‘: 18} 2 k4 3 2 4 k3 5 k1
ps3:
循环他的values()
1 info = { 2 "k1": 18, 3 2: True, 4 "k3": [ 5 11, 6 [], 7 (), 8 22, 9 33, 10 { 11 ‘kk1‘: ‘vv1‘, 12 ‘kk2‘: ‘vv2‘, 13 ‘kk3‘: (11,22), 14 } 15 ], 16 "k4": (11,22,33,44) 17 } 18 for item in info.values(): 19 print(item)
执行结果:
1 {2: True, ‘k4‘: (11, 22, 33, 44), ‘k1‘: 18, ‘k3‘: [11, [], (), 22, 33, {‘kk2‘: ‘vv2‘, ‘kk3‘: (11, 22)}]} 2 True 3 (11, 22, 33, 44) 4 18 5 [11, [], (), 22, 33, {‘kk1‘: ‘vv1‘, ‘kk2‘: ‘vv2‘, ‘kk3‘: (11, 22)}]
ps4:
即想获取key,又想获取values
1 info = { 2 "k1": 18, 3 2: True, 4 "k3": [ 5 11, 6 [], 7 (), 8 22, 9 33, 10 { 11 ‘kk1‘: ‘vv1‘, 12 ‘kk2‘: ‘vv2‘, 13 ‘kk3‘: (11,22), 14 } 15 ], 16 "k4": (11,22,33,44) 17 } 18 for item in info.keys(): #即想获取key,又想获取values 19 print(item,info[item])
执行结果:
1 {‘k4‘: (11, 22, 33, 44), 2: True, ‘k3‘: [11, [], (), 22, 33, {‘kk2‘: ‘vv2‘, ‘kk3‘: (11, 22)}], ‘k1‘: 18} 2 k4 (11, 22, 33, 44) 3 2 True 4 k3 [11, [], (), 22, 33, {‘kk2‘: ‘vv2‘, ‘kk1‘: ‘vv1‘, ‘kk3‘: (11, 22)}] 5 k1 18
ps5:
获取键值对
1 info = { 2 "k1": 18, 3 2: True, 4 "k3": [ 5 11, 6 [], 7 (), 8 22, 9 33, 10 { 11 ‘kk1‘: ‘vv1‘, 12 ‘kk2‘: ‘vv2‘, 13 ‘kk3‘: (11,22), 14 } 15 ], 16 "k4": (11,22,33,44) 17 } 18 for k,v in info.items(): 19 print(k,v)
执行结果:
1 {‘k1‘: 18, 2: True, ‘k4‘: (11, 22, 33, 44), ‘k3‘: [11, [], (), 22, 33, {‘kk2‘: ‘vv2‘, ‘kk3‘: (11, 22)}]} 2 k1 18 3 2 True 4 k4 (11, 22, 33, 44) 5 k3 [11, [], (), 22, 33, {‘kk2‘: ‘vv2‘, ‘kk1‘: ‘vv1‘, ‘kk3‘: (11, 22)}]
ps6:
True 1 False 0
1 info ={ 2 "k1": ‘asdf‘, 3 True: "123", 4 # [11,22]: 123 5 (11,22): 123, 6 # {‘k1‘:‘ v1‘}: 123 7 8 } 9 print(info)
执行结果:
1 {True: ‘123‘, ‘k1‘: ‘asdf‘, (11, 22): 123}
ps7: 打印序号,并取出key和value的值
1 #打印序号,并取出key和value的值 2 dic = {‘k1‘:123,123:123,‘999‘:123} 3 for i,v ,in enumerate(dic.items(),1): 4 print(i,v[0],v[1]) 5 6 for i,v in enumerate(dic,1): 7 print(i,v,dic[v])
复习字典:
字典:{},列表:[], 元组:()
总结:
1、字典key:value
2、字典的value的值可以是任何值
3、布尔值、列表、字典不能作为字典的key,但元组可以,做为列表的key
4、字典是无序的
一、字典的增加,删除,修改,查询
示例:
1 info={‘nulige‘: 28, ‘alex‘: 30, ‘liuyang‘: ‘man‘, ‘wusir‘: ‘woman‘}
1、增加和修改
增加key和vlaue
1 #修改value 2 info[‘nulige‘]=18 3 print(info) 4 5 #增加 6 info.update({‘sunkai‘:18}) 7 print(info) 8 9 #增加key和vlaue(没有就增加,有就修改) 10 info[‘lihuafen‘]=35 11 print(info)
往字典的列表中加入元 素
1 #往wusir字典中加入一个元素44 2 3 info={‘nulige‘: 28, ‘alex‘: 30, ‘liuyang‘: ‘man‘, ‘wusir‘: [11,22,33]} 4 info[‘wusir‘].append(44) 5 print(info) 6 7 8 #往wusir字典的第一个位置插入个元素18 9 info={‘nulige‘: 28, ‘alex‘: 30, ‘liuyang‘: ‘man‘, ‘wusir‘: [11,22,33]} 10 info[‘wusir‘].insert(0,44) 11 print(info)
2、删除
1 #删除 2 del info[‘nulige‘] 3 print(info) 4 5 #删除 6 info.pop(‘alex‘) 7 print(info) 8 9 #清空字典 10 info.clear() 11 print(info) #{}
3、查询
获取字典的key和values
1 #取字典的key 2 3 #法1: 4 for item in info: 5 print(item) 6 7 #法2: 8 for item in info.keys(): 9 print(item) 10 11 #取字典的values 12 for item in info.values(): 13 print(item) 14 15 #取key和values 16 for item in info.keys(): 17 print(item,info[item])
4、获取字典键值对应的值
1 for k,v in info.items(): 2 print(k,v) 3 4 #结果: 5 nulige 28 6 alex 30 7 wusir woman 8 liuyang man
5、打印序号,取key和value
1 info={‘nulige‘: 28, ‘alex‘: 30, ‘liuyang‘: ‘man‘, ‘wusir‘: ‘woman‘} 2 3 法一: 4 for i,v,in enumerate(info.items(),1): 5 print(i,v[0],v[1]) 6 7 法二: 8 for i,v in enumerate(info,1): 9 print(i,v,info[v]) 10 11 执行结果: 12 1 nulige 28 13 2 alex 30 14 3 wusir woman 15 4 liuyang man
6、计算字典总个数
1 info={‘nulige‘: 28, ‘alex‘: 30, ‘liuyang‘: ‘man‘, ‘wusir‘: ‘woman‘} 2 print(len(info)) 3 4 #执行结果: 5 4
五、整理必须掌握的东西
一、数字int(..) 二、字符串replace/find/join/strip/startswith/split/upper/lower/formattempalte = "i am {name}, age : {age}"# v = tempalte.format(name=‘alex‘,age=19)v = tempalte.format(**{"name": ‘alex‘,‘age‘: 19})print(v) 三、列表append、extend、insert索引、切片、循环 四、元组忽略索引、切片、循环 以及元素不能被修改 五、字典get/update/keys/values/itemsfor,索引 dic = { "k1": ‘v1‘} v = "k1" in dicprint(v) v = "v1" in dic.values()print(v) 六、布尔值0 1bool(...)None "" () [] {} 0 ==> False