dict function: 1, you can use the Dict function, through other mappings or such sequence pairs to build a dictionary.
2. You can also create a dictionary by using keyword parameters.
Basic Dictionary operations:1, Len (d): Returns the number of key-value pairs in D
2, D[k]: Returns the value associated to the key K
3. D[K]=V: Associate the value V to the key K
4. del d[k]: Delete key to K
5, k in D: Check D for any items with a key k
1, the key can be any immutable type
2. Add automatically: Even if the key does not exist in the dictionary at first, it can be assigned a value so that the dictionary creates a new entry. And the list does not.
the formatted string of the dictionary:% followed by the (key), followed by the other explanatory elements.
Dictionary method:1, clear: Clears all items in the dictionary. (In-place operation, no return value) in case 1, by associating X with a new empty dictionary to ' empty ' it, which has no effect on Y, it is also associated to the original dictionary. In case 2, the original dictionary is emptied, and y is then emptied.
2. Copy: Returns a new dictionary with the same key-value pair. (Shallow copy, when a value is substituted in a copy, the original dictionary is unaffected, but if a value is modified (in-place, not replaced), the original dictionary also changes because the same value is stored in the original dictionary)
deepcopy function: Deep copy, copy all of the values it contains.
3, Fromkeys: Using the given key to create a new dictionary, each key default corresponding value is None.
4. Get: Access dictionary entries. Generally speaking, accessing an item that does not exist in a dictionary can be an error, and a get does not. You can also customize the default values to replace None.
5, Has_key: Check whether the dictionary contains the key given. D.has_key (k) equivalent to K in D
6. Items and Iteritems:items return all dictionary items to the list, each of which comes from (key, value). However, the items are returned with no special order.
7. The keys and Iterkeys:keys methods return the keys in the dictionary as a list, and Iterkeys returns an iterator for the key.
8, Pop: Get the value corresponding to the given key, and then remove the key value pair from the dictionary.
9, Popitem: Popup random key value pairs.
10. SetDefault: When the key does not exist, SetDefault returns the default value and updates the dictionary accordingly. If the key exists, it returns its corresponding value, but does not change the dictionary.
11. Update: Updates another dictionary with one dictionary item. The items in the provided dictionary are added to the old dictionary and overwritten if the same key is available.
12. Values and Itervalues:values methods return the value in the dictionary as a list, itervalues the iterator that returns the value, and, unlike the return key, it can contain duplicate elements in its return list.
Basic Python Tutorial (4)