python基础入门---字典操作
#key-value info = { ‘stu1101‘: "luyi", ‘stu1102‘: "yuanjinxia", ‘stu1103‘: "situomo", } for i in info: print(i,info[i]) for k,v in info.items():#先转成列表再打印 print(k,v) ‘‘‘ b = { ‘stu1101‘:"qjh", 1:3, 2:5 } info.update(b)#更新操作 #print(info) #字典打印出来是无序的,key必须是唯一的,天生去重 #print(info["stu1101"]) #info["stu1101"] = "lichanggeng" #info["stu1104"] = "jinyizhixia" print(info) c = dict.fromkeys([6,7,8],[1,{"name":"qjj"},444]) print(c) c[7][1][‘name‘]="jack" print(c) #print(info.items())#把字典转成列表 #del #删除操作 #del info["stu1101"] #info.pop("stu1101") #info.popitem()#随便删除 #print(info) # info [‘stu1103‘] # print(info.get(‘stu1103‘)) # print(‘stu1108‘in info) ‘‘‘
相关推荐
sifeimeng 2020-06-21
阿斌Elements 2020-05-05
songerxing 2020-05-03
yixiaoqi00 2020-04-22
要啥自行车一把梭 2020-04-17
随心而作 2020-04-07
JayFighting 2020-04-07
80327065 2020-03-09
woxmh 2020-03-04
hgzhang 2020-02-18
时光如瑾雨微凉 2020-02-02
winmeanyoung 2020-01-29
wyqwilliam 2020-01-17
typhoonpython 2020-01-12
sofast 2020-01-08
KaiZhaoKZ 2019-12-29
snowpage 2014-07-10