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

How to write an empty dictionary in python

(*-*)浩
Release: 2019-08-02 11:08:27
Original
8137 people have browsed it

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 }
Copy after login

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 = {}
Copy after login

When assigning

dict[key1]=value1 
dict[key2]=value2
Copy after login

, the dictionary is:

dict = {key1:value1,key2:value2}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template