First, what is a dictionary
1. The dictionary is the only type of mapping in Python, consisting of key-value pairs enclosed in {},
2. The key of the element in the dictionary: must be a hash immutable data type that can be used as a key in the dictionary
3. The value of the element in the dictionary: there is no limit to what data type can be
Second, the dictionary additions and deletions to search
1. Increase
Dic[key]=value add directly (Key:value) (this method can also be used to modify the dictionary)
Dic.setdefault (Key,value) If the key is already present in the dictionary, do nothing, otherwise add (Key:value)
Do not enter the value parameter to query, if not the key will return none
2. By deleting
Pop (key) has a return value that returns the value corresponding to key
Del Dic[key] Delete key and his corresponding value (del dic = delete entire dictionary, again query cannot find this dictionary)
Popitem () random Delete, latest Python version delete last key value pair
Clear () Empty dictionary dictionary into empty Dictionary {}
3. Change
Dic[key] = value forced modification
Dic.update (dictionary) The old Dictionary before the new dictionary is overwritten
4. Enquiry
Dic.get (Key)
For loop
Dic[key]
SetDefault (mentioned above)
Third, the special operation of the dictionary
Dic.keys gets all the keys in the dictionary stored in a high-copy list
Dic.values gets all the values in the dictionary stored in a high-copy list
Dic.items gets all the key-value pairs in the dictionary in a high-copy list
Iv. Deconstruction
A, B = (a=1,b=2)
A, B = "a" (a=1,b=2)
V. Nesting of dictionaries
Similar to the list of nesting!
A dictionary of Python data types