Initialize an Empty Dictionary in Python (original) (raw)

Last Updated : 12 Apr, 2025

To initialize an empty dictionary in Python, we need to create a data structure that allows us to store key-value pairs. Different ways to create an Empty Dictionary are:

Use of{ }symbol

We can create an empty dictionary object by giving no elements in curly brackets in the assignment statement.

Python `

d = {}

print(d) print("Length:", len(d)) print(type(d))

`

Output

{} Length: 0 <class 'dict'>

Use of dict() built-in function

Empty dictionary is also created by dict() built-in function without any arguments.

Python `

d = dict()

print(d) print("Length:",len(d)) print(type(d))

`

Output

{} Length: 0 <class 'dict'>

Initialize a dictionary

This code demonstrates how to create an empty dictionary using a dictionary comprehension. It initializes d with no elements and then prints the dictionary, its length, and its type.

Python `

d = {key: value for key, value in []}

print(d) print("Length:", len(d)) print(type(d))

`

Output

{} Length: 0 <class 'dict'>

**Related Articles:

Similar Reads