Dictionary:
Simple dictionary:
DIC = {1: ' A ', 2: ' B ', 3: ' C '}
Nested dictionaries: Dictionaries can contain tuples, lists, dictionaries
DIC = {1: ' A ', 2: ' B ', 3: ' C ', 4:{1: ' A ', 2: ' B ', 3: ' C '},5:[1,2,3],6: (5,6)}
Dic.clear () empty
Dic.fromkeys (iterable, Value=none,/) don't understand what's the use
Dic.items () Displays all key-value pairs in the dictionary
Dic.pop (K[,d]) popup K for key, must be specified, return the popup value;d is the default, when key does not exist the return value is default, if you do not specify default will error
Dic.setdefault (K[,d]) sets the default value, K represents key,d for default, and when key does not specify a value, the value is the default
Dic.values () Displays all value, does not display key
Dic.copy () copy dictionary, with new ID, generally get new dictionary by Dic1 = Dic.copy ()
Dic.get (K[,d]) gets the key value K for key,d represents default and returns Default,default default is None when key does not exist
Dic.keys () Displays all keys, does not display value
Dic.popitem () Popup key value pair, from left to right pop up, cannot specify, return value is popped key,value
Dic.update ([E,]**f) update, E is a dictionary or iterable, the value of key is updated when key is present, and a new key,value is appended when it can not exist.
The above common have get update copy
Print:
For key in DIC:
Print (Dic[key])
The key is traversed, and when value is a list or dictionary, it can be nested through a for loop
Python3 Dictionary of Learning