Home  >  Article  >  Backend Development  >  How to write an empty dictionary in python

How to write an empty dictionary in python

(*-*)浩
(*-*)浩Original
2019-08-02 11:08:278061browse

Dictionary is another mutable container model and can store any type of object.

How to write an empty dictionary in python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn