# "dictionary" #映射 #字典是无序存储的, no positional relationship print (ID (a)) #打印a的内存地址 #不可变类型: Integer, String, tuple #可变类型: list, dictionary Dictionary = {' name ': ' Zhangw ', ' age ': +, ' isboy ': True,} dictionary2 = {' name ': ' Haha ', ' What ': ' Qie '} #字典可以做值, cannot do key # Dictionary name {key: Value, key: Value} #字典两大特点 #无序 #键唯一 #增加 dictionary[' name '] = dictionary[' haha ') = ' new ' ret= Dictionary.setdefault (' age ', +) #键存在, does not change, returns the corresponding value in the dictionary, the key does not exist, adds a new key-value pair in the dictionary, and returns the corresponding value #查找 #通过键 Print ( dictionary[' name ']) print (Dictionary.keys ()) #查找键 #查找出来的是dict_key类型 print (Dictionary.values ()) print (Dictionary.items ()) #修改 dictionary.update (dictionary2) #删除 del dictionary[' name '] #根据键删除 dictionary.clear () #清空字典 del.dictionary #删除整个字典 #排序 sorted (dictionary)
"Python"--Dictionary