Write a statement that creates an empty dictionary.
Create an empty dictionary contains two approaches.
First approach:
# Using curly brackets {}
my_dict = {} # Creating an empty dictionary using curly brackets
Explanation:
{}
: This method is straightforward, where you simply assign an empty set of curly brackets to the variable my_dict
.Second approach:
#Using dict() constructor
my_dict = dict() # Creating an empty dictionary using dict() constructor
Explanation:
dict()
constructor: The dict()
constructor is another way to create an empty dictionary.dict()
without any arguments, it creates a new empty dictionary and assigns it to the variable my_dict
.