Initialize an Empty Dictionary in Python

Dictionary in Python is an unordered collection of data values, used to store data values like a map, which unlike other Data Types that hold only single value as an element, Dictionary holds key:value pair. Key value is provided in the dictionary to make it more optimized. 

Now, Let’s see the different ways to  create Empty Dictionary.

Method 1: Use of { } symbol.

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

Code:



Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 code to demonstrate use of  
# {} symbol to initialize dictionary
emptyDict = {}
  
# print dictionary
print(emptyDict)
  
# print length of dictionary
print("Length:",len(emptyDict))

chevron_right


Output:

{}
Length: 0

Method 2: Use of dict() built-in function.

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

Code:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 code to demonstrate use of  
# dict() built-in function to 
# demonstrate initialize dictionary
emptyDict = dict()
  
# print dictionary
print(emptyDict)
  
# print length of dictionary
print("Length:",len(emptyDict))

chevron_right


Output:

{}
Length: 0
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.