Python Example to Clear or Empty Dictionary

Delete all items of a Python Dictionary

To clear or empty a dictionary, which means deleting all the items in the dictionary, use clear() function.

In this tutorial, we shall learn how to clear all the items in a Python Dictionary using Dictionary.clear() function, with the help of syntax and well detailed example Python programs.

Syntax – Dictionary.clear()

Following is the syntax to clear items in a Dictionary.


The elements in the original dictionary are removed. This operation results in a loss of data. So, exercise caution while you call clear() on Dictionary.

Example 1: Clear all items of a Python Dictionary

We will create a dictionary, initialize it with some key:value pairs and delete all of them using clear() function.

Python Program

myDictionary = {
	"a": 65,
	"b": 66,
	"c": 67

# print the dictionary items
print('Dictionary items:\n',myDictionary)

# clear the dictionary

# print the dictionary items
print('Dictionary items after clear():\n',myDictionary)


Dictionary items:
 {'a': 65, 'b': 66, 'c': 67}
Dictionary items after clear():


In this tutorial of Python Examples, we learned how to clear or empty a Python Dictionary using clear(), with the help of well detailed Python example programs.