Data Type-Dictionary
A dictionary is a Key-value data type, used as a dictionary of our school, to check the details of the corresponding page by strokes and letters.
Characteristics:
Key-value structure
Key must be hash, must be immutable data type, must be unique
can store any number of values, can be modified, can not be unique
Disordered
Fast Search Speed
Query Info.get () without this key will not error, info[] Without this key, will error, keyerror
Info.values () Remove value
Info.keys () Remove the key value
Info.setdefault () If there is this key, the value of this key is returned, and if there is no key, the dictionary is added
Info.update (b), add the Key-value in dictionary b to the info dictionary, if there is a duplicate key, then overwrite the key value, if there is no repetition, join
Info.items () produces a list of dictionary elements
Info.fromkeys () Generate default dict from a list, there's a pit that can't be explained, try to use less
Multilevel nesting of dictionaries
There are two types of loops:
1.for Key in Info:
Print (Key,info[key])
This method is simple, quick, and often used
2.for k,v in Info.items ():
Print (K,V)
This method will first convert the dictionary into a list, and then loop, execution efficiency is not the first method of high,
The 11-day Python Learning record 2