1. Dictionaries
Dict using {} to represent key value pair data {Key:value} Uniqueness
Key must be a hash immutable data type that can be used as a key in the dictionary
there is no limit to the value
Dict saved data is not saved in the order that we added it. It is stored in the order of the hash table. And the hash table is not sequential. Therefore, the slicing work is not possible.
It can only get the data in Dict by key.
Note: Key must be immutable (hashed). value is not required. Can save any type of data
2. Adding and deleting changes
1) Increase
Dic[key] = value
Dic.setdefault (Key,value) if the key exists in the dictionary without any action, add
Can be queried by key, without this key to return none
====================================================================
2) Delete
Pop (key) has a return value that is returned by the deleted value
Del Dic[key]
Popitem () random deletion
Clear () empty Dictionary
======================================================================
3) Modify
Dic[key] = value
Dic.update (dictionary)
=======================================================================
4) Query
Get (Key)
Dic[key]
For loop
SetDefault (Key)
=======================================================================
3. Other operations of the dictionary:
Keys gets to all the keys that exist in a high-imitated list
Values gets to all the values that exist in a high-imitated list
Items gets to all the key values in the form of a meta-ancestor exist in a highly imitated list
Deconstruction:
A, B = 1, 2
A , B = (up to)
b = [+]
4. Nesting of dictionaries:
DIC = {
' Name ': ' Wang Feng ',
' Age ': 43,
' Wife ': {
' Name ': ' International Chapter ',
' Age ': 39,
' Salary ': 100000
},
' Baby ': [
{' name ': ' Big Bear ', ' age ': 18},
{' name ': ' Bear II ', ' age ': 15},
]
}
dic[' baby '][0][' age ' = 19
Print (DIC)
Python Basics (v)