Dictionary and a list of differences:
- The list is ordered
- A dictionary is unordered
- Dictionary definitions using {}
- Using the key-value dictionary of stored data, using key-value pairs between "," separator
- Key index is key
- Value is the value of the data
- Use between the key and value a ';'
- The key is the only
- Value can be any data, the key can only be strings, numbers, or the tuple
Dictionary of operation:
xiaoniu_dict = {"name" : "xiaoniu", "age" : 21} # 取值 print("********取值************") print(xiaoniu_dict["name"]) # 增加 print("********增加************") xiaoniu_dict["height"] = 1.65 print(xiaoniu_dict) # 修改 print("******** 修改************") xiaoniu_dict["age"] = 22 print(xiaoniu_dict) # 删除 print("********删除************") xiaoniu_dict.pop("height") print(xiaoniu_dict) # 合并 print("********合并************") temp_dcit = {"height" :1.65} xiaoniu_dict.update(temp_dcit) print(xiaoniu_dict) # 清空 print("*******清空************") xiaoniu_dict.clear() print(xiaoniu_dict)
result: