Dictionary features:
The dictionary is unordered. It cannot be accessed through offset, but can only be accessed through keys.
Dictionary = {'key': Value} key: similar to our actual key, while value is a lock. One key opens one lock
Detailed features:
There is no internal order. The key is used to read the content, which can be nested and merged, so that we can organize multiple data structures and modify the content in the same place, which is of a variable type.
The keys that make up the dictionary must be unchangeable data types, such as numbers, strings, tuples, lists, and other variable objects.
1. Create a dictionary dynamically. {}, Dict ()
Info = {'name': 'lilei', 'age': 20}
Info = dict (name = 'lilei', age = 20)
2. Add the inserted content A ['xx'] = 'xx'
For example, info ['phone'] = 'iphone5'
3. Modify the update content A ['xx'] = 'XX ',
Info ['phone'] = 'htc'
The update parameter is a dictionary type that overwrites the value of the same key.
Info. Update ({'city': 'beijing', 'phone': 'nokia '})
HTC becomes Nokia
4. Delete del, clear, and pop.
Del info ['phone'] deletes an element.
Info. Clear () delete all elements of the dictionary
Info. Pop ('name ')
5 In and has_key () member operations to determine whether an element exists.
For example:
1 phone in info
2 info. has_key ('phone ')
6 keys (): The returned list contains all the keys of the dictionary.
Values (): The returned list contains all the values in the dictionary.
Items: the container that generates a dictionary: [()]
7 get: Get a value from the dictionary
Info. Get ('name ')
Info. Get ('age2', '22 ')
Address: http://www.cnpythoner.com/post/246.html