How to Create an Empty Dictionary in Python? - Tutorial Kart

[Pages:3]How to Create an Empty Dictionary in Python?

Python ? Create an Empty Dictionary

To create an empty Dictionary in Python, we can use dict() built-in function with no argument passed to it or take empty flower brackets and assign it to a variable. The syntax to crate an empty Python Dictionary using dict() function is

myDictionary = dict()

The syntax to create an empty Python Dictionary using flower brackets is

myDictionary = {}

Example 1 ? Create Empty Dictionary using dict() function

In this example, we will create an empty dictionary using dict() builtin function. We shall print the type of the object returned by dict() and print the object itself. Python Program

myDictionary = dict() print(type(myDictionary)) print(myDictionary)

Output

{}

Example 2 ? Create Empty Dictionary using Flower Braces

In this example, we will create an empty dictionary with empty flower brackets. Python Program

myDictionary = {} print(type(myDictionary)) print(myDictionary)

Output

{}

Conclusion

In this Python Tutorial, we learned how to create an empty Python Dictionary with the help of example programs.

Python Programming

Python Tutorial Install Python Install Anaconda Python Python HelloWorld Program Python Variables Python Variable Data Type Conversion Python Comments

Control Statements

Python If Python If Else Python While Loop Python For Loop

Python String

Python String Methods Python String Length Python String Replace Python Split String Python Count Occurrences of Sub-String Python Sort List of Strings

Functions

Python Functions

Python Collections

Python List Python Dictionary

Advanced

Python Multithreading

Useful Resources

Python Interview Questions

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download