How to Create an Empty Dictionary in Python
To create an empty dictionary in Python, you can use {} curly braces or the dict() function.
The following examples show how to create an empty dictionary in Python using two different methods.
Using {} Curly Braces
We can use {} curly braces to create an empty dictionary.
Let’s see how to use {} curly braces in Python:
# Create empty dictionary
dict_ = {}
# Show dictionary
print(dict_)
Output: 👇️
{}
The output shows the empty dictionary created using {} curly braces.
Using dict() Function
We can use the dict() function to create an empty dictionary.
Let’s see how to use the dict() function in Python:
# Create empty dictionary
dict_ = dict()
# Show dictionary
print(dict_)
Output: 👇️
{}
The output shows the empty dictionary created using the dict() function.
Conclusion
We can use {} curly braces or the dict() function to create an empty dictionary in Python.