Dictionary:
Unique mapping type in Pytho, unordered list (hash table)
Objects are mutable, but dictionary keys must use immutable objects, and different types of key values can be used in a dictionary
Definition method:-{} such as: Dic={name: ' Zzc ', Age:19,gender: ' Man '}
-Using the Factory Method Dict () column fdict=dice ([' X ', 1],[' Y ', 2])
-Built-in method: Fromkeys () The elements in the dictionary have the same value, default to None
Column: Ddict=[].fromkeys (' x ', ' Y '),-1)
Operation:
-Added: dic[' key ']= ' value '
-Modified: dic[' key ']= ' value '
-Delete a key and Value:del (dic[' key ') in the dictionary
-Delete and display the deleted value after deletion: dic.pop[' key '
-Delete all elements of the Dictionary: Dic.clear ()
-Delete entire dictionary: del dic
Method of the Dictionary:
+dic.clear: Delete all elements in the dictionary
+dic.fromkeys (Seq,val=none) creates and returns a dictionary with the elements in the SEQ, and Val is the default value set
+dic.get (Key,default=none): Returns the value of key if the key does not exist return Fefault specified
+dic.has_key (Key): Determine if there is a key in the dictionary, it is recommended to use in and not in instead of
+dic.keys () returns a list of keys in the dictionary
+dic.items () Returns a list of the corresponding tuples of the key value
+dic.iter* () Iteritems () Iterkeys () returns the iteration value instead of the list
+dic.setdefault (Key,default=none) with set, if key exists return its value, if key does not exist Dic[key]=default
+dic.update (DIC1) adds the key-value pairs in the Dic1 to the dictionary dic, and if duplicates overwrite, entries that do not exist in the original dictionary are added
+dic.valuse () Returns a list of all values in the dictionary
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Python Learning note 06-Dictionaries