⼀. Dictionary brief
Dictionary (dict) is the only ⼀ in the python ⼀ type mappings. He is enclosed in {} key-value pairs in the key is dict
Only ⼀ In saved, ⼀ calculated memory address according to a key. The key-value is then stored in the address.
Such an algorithm is called a hash algorithm, therefore, remember, key-value stored in the dict key 'must be a hash,
If you do not understand what is hash, temporarily, so remember, you can not change are the hash,
So you can hash it means immutable. This is in order to accurately calculate the memory address ⽽ provisions.
Hashable known (non-variable) data types: int, str, tuple, bool
Not be hashed (variable) data types: list, dict, set
Syntax:
{key1: value1, key2: value2....}
Note:. Key must be immutable (hashable) the value does not require any type of data can be stored.
# Legal
dic = {123: 456, True: 999, "id": 1, "name": 'sylar', "age": 18, "stu": ['帅
Brother ',' US ⼥ '], (1, 2, 3):' twist vine '}
print (say [123])
print(dic[True])
print(dic['id'])
print(dic['stu'])
print (say [(1, 2, 3)])
# illegal
# Dic =. {[1, 2, 3]: 'Jay'} # list is not a key variable
# Dic =. {{1: 2}: "ha"} # dict is not a key variable
dic = {{1, 2, 3}: 'oh oh'} # set is variable, as the key can not be
dict saved data is not added to it in accordance with our order to save. is in the order of hash tables to save. ⽽ hash table
Not continuous, so it is not supported while slicing ⼯ make. It can only be acquired through key data in dict
⼆. Dictionary CRUD and other related operations
1. Increase
2. Delete
3. Modify
4. Query
Using the key query shoots as usual to find specific data.
5. Other related operations
III. Nested dictionary