Dictionary is another mutable container model and can store any type of object.
Each key-value (key=>value) pair in the dictionary is separated by a colon (:), and each pair is separated by a comma ( ,), and the entire dictionary is enclosed in curly braces ({}).
The format is as follows: (Recommended learning: Python video tutorial)
d = {key1 : value1, key2 : value2 }
The keys must be unique, but the values No need.
The value can be of any data type, but the key must be immutable, such as string, number or tuple.
An empty dictionary instance:
dict = {}
When assigning
dict[key1]=value1 dict[key2]=value2
, the dictionary is:
dict = {key1:value1,key2:value2}
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to write an empty dictionary in python. For more information, please follow other related articles on the PHP Chinese website!