标签:pre 元素 update 没有 get print 随机 pytho size
dict 增删改查
dic1 = {‘age‘: ‘19‘, ‘name‘: ‘jing‘, ‘sex‘: ‘male‘} #增 # dic1[‘high‘] = 17 # dic1.setdefault(‘weight‘) # dic1.setdefault(‘weight‘, 150) #删 # dic1.pop(‘name‘) # dic1.pop(‘nnnn‘, ‘没有此键‘) # dic1.popitem() # 3.5随机删除 3.6+删最后一组 # dic1.clear() # del dic1[‘name‘] # print(dic1) #改 # dic1[‘high‘] = 185 # dic2 = {‘age‘: ‘18‘, ‘name‘: ‘jin‘, ‘3‘: ‘33‘} # dic2.update(dic1) # dic1中的元素覆盖添加到dic2中 # print(dic2) #查 # print(dic1.keys()) # print(dic1.values()) # print(dic1.items()) # for i in dic1.items(): # print(i) # for k,v in dic1.items(): # print(k,v) # print(dic1.get(‘name‘, ‘没有这个键‘))
标签:pre 元素 update 没有 get print 随机 pytho size
原文地址:https://www.cnblogs.com/ethan2018/p/9153126.html