Python 调用内部的哈希函数,将字典的键作为参数进行转换,得到一个唯一的地址,用于存放值(这也就解释了为什么给相同的键赋值会直接覆盖,因为相同的键转换后的地址是一样的)
删除元素 dict_2 = {'lilei': 89, 'hanmeimei': 99, 'tom': 99} dict_2.pop("tom") print(dict_2) #{'lilei': 89, 'hanmeimei': 99}
遍历 dict_3 = {'lilei': 89, 'hanmeimei': 99} for key in dict_3: print(key,dict_3[key]) for value in dict_3.values(): print(value) for k,v in dict_3.items(): print(k,v) for index,v2 in enumerate(dict_3): print(index,v2) #lilei 89 #hanmeimei 99 #89 #99 #lilei 89 #hanmeimei 99 #0 lilei #1 hanmeimei
转载于:https://www.cnblogs.com/byadmin/articles/foundation-4.html