Dictionary (dictionary)
The dictionary has a concept key (key) and the corresponding values (value)
For example:
Phone = {' rom ': 13760413131, ' valley ': 13927434343, ' Helen ': 1355101535}
Features of the dictionary:
1. Define a dictionary with curly braces {}
2. The key and value in each dictionary are concatenated with a colon, indicating that they are a group of
3, in each group behind, comma table separated
How to do the dictionary:
1. Find the Valley Phone
Print (phone[' valley ')
2. Add a new element to the dictionary
phone[' Yellow ']=345
3. Modify the value of an element in the dictionary
phone[' Yellow ']=678
4. Remove an element from the dictionary
Del phone[' [ROM]
5. Empty all the elements in the dictionary at once
Phone.clear ()
6. Delete the dictionary directly
Del phone
Features of the dictionary:
1, in a dictionary, the key is not allowed to appear the same name
2. The key in the dictionary is immutable, so the list cannot be used in the dictionary
Functions and methods of dictionaries
1. CMP (DICT1,DICT2) compares two dictionary elements
2. Len (dict) Number of statistical dictionary elements
3. STR (dict) output dictionary printable string representation
4, type (variable) returns the type of the variable entered, and returns the dictionary type if the variable is a dictionary.
Python Dictionary (dictionary)