Dictionary: Dictionaries are unordered, no order. There is a list at the subject, all is in order
Composed of fields: key - value
Dictionary Guming Si Yee, can store a lot of things, and through key can quickly query the corresponding value
Dictionary definitions
name ={
name1 = "xiaohong",
name2 = "xiaobai"
}
Method to query the value (this method can only query key already exists, if the key does not exist query will complain)
print(name[“name1”])
Optimized version of the query method
print (name.get (name3)) will return this time none
print (name.get (name2)) return this time "xiaobai"
See if the key already exists in the dictionary
print ( "name2" in name) exists, false return ture does not exist
Modify name1
name [name1] = "red"
New name3
name [name3] = "Li"
Delete name3
del name[name3]
Delete name dictionary table
del name
Another way to delete name3
name.pop("name3")
Random deleted
name.popitem()