1. Format
Variable name = {“key”:“value1”,“key2”:value2,“key3”:value3}
2.
(1). Modifying elements : You can modify elements , adopt key find , You can modify
(2). Additive elements : Variable name [“key”]=“value”
If you are using Variable name [‘ key ’] = data when , This “ key ” In the dictionary , Then modify the data , non-existent , So it's going to add this element
(3). Add new elements Variable name [‘ new key’]=“value”
(4). Remove elements del clear( Empty )
(5).len() In the measurement dictionary , The number of key-value pairs
print(len( Variable name ))
(6).keys Return a dictionary containing all KEY A list of
print( Variable name .keys())
(7).values Return a dictionary containing all value A list of
print( Variable name .value())
(8).items Return one containing all ( key , value ) The list of Yuanzu
print( Variable name .items())
3. Traversal of dictionaries
Traversing the dictionary key key
a = {“name”:“aa”,“age”:15,“sex”:“ male ”}
for key in a.keys():
print(key)
Traversing the dictionary value value
a = {“name”:“aa”,“age”:15,“sex”:“ male ”}
for value in a.values():
print(value )
Yesterday, Xiaobian received a
List of articles 1. Last artic