1. Dictionary: in Python, a dictionary is a series of key-value pairs. Each key is associated with a value, and you can use the key to access the value associated with it. The values associated with the key can be numbers, strings, lists, and dictionaries. You can actually use any Python object as a value in the dictionary.
The dictionary is unordered, because there is no subscript, and the key is indexed, so it is unordered.
The key of the dictionary must be unique, because it is indexed by key, so key cannot be duplicated.
#字典的增:
names = {' them ': ' Dawn ', ' Move ': ' The Bureau '}
names[' happy '] = ' green orange ' #增加一个key
Names.setdefault (' No Xiao ', ' green orange ') #如果key只存在, will not change the original value, if it does not exist will be appended to the back of the dictionary
names[' them '] = ' Broken Board ' #如果key存在的话就修改原来的值
#字典的改
names = {' them ': Breaking the Bureau ', ' Move Mountain ': ' The Bureau '}
names[' Move Mountain heritage '] = ' sleepy ' #修改其键值为榣山遗韵的value
#字典的查
names={' them ': ' The Bureau ', ' Move Mountain ': ' Breaking the Bureau '}
Print (Names.get (' them language ')) #获取key为谩语的value
Print (Names.get (' them language ')) #取不到key为谩语, default is 110
#字典的删除
names = {' them ': ' The Bureau ', ' Move Mountain ': ' Breaking the Bureau '}
Names.pop (' them language ') #删除指定key的values
Names.popitem () #随机删除一个key
Del names[' Move Mountain heritage ' #指定key来删除
Names.clear () #清空字典
Some common methods used in dictionaries are:
names = {' them ': ' The Bureau ', ' Move Mountain ': ' Breaking the Bureau '}
Print (Names.values ()) #获取字典中所有的values
Print (Names.key ()) #获取字典中所有的key
Print (Names.items ()) #获取字典中所有的key-values
Python Dictionary (Dictionary)