Python Empty Dictionary

Empty Dictionary in Python

You can create an empty dictionary in Python in many ways.

In this tutorial, we will present you examples in some of the ways to create an empty Python dictionary.

Examples

1. Create an empty Dictionary using {}

You can assign empty curly braces to a variable, and the variable is initialized to a Dictionary with no key:value pairs.

Python Program

myDict = {}

print(type(myDict))
print(myDict)
Run Code Copy

Output

<class 'dict'>
{}

An you can see the output, empty Python dictionary is created.

2. Create an empty Dictionary using dict()

There is also another way of creating an empty dictionary in python. And that is using dict() built-in function. Provide no arguments to dict() function, and it returns an empty dictionary.

Python Program

myDict = dict()

print(type(myDict))
print(myDict)
Run Code Copy

Output

<class 'dict'>
{}

Summary

In this tutorial of Python Examples, we learned how to create an empty dictionary using initialisation, or dict() built-in function, with the help of well detailed examples.

Related Tutorials

Code copied to clipboard successfully 👍