In this Python tutorial, you will learn what clear() method of dictionary dict class does, its syntax, and how to use this method to remove all the items in a dictionary, with example programs.

Python Dictionary clear()

Python Dictionary clear() method removes all the items from the dictionary. All data in the dictionary will be lost and the length of the dictionary becomes zero.

In this tutorial, we will learn how to clear all items of a dictionary using clear() method.


The syntax of dict.clear() is


clear() method returns None.



In this example, we will take a dictionary with some initial key:value pairs, and clear all the items by calling clear() method on the dictionary.

Python Program

myDictionary = {'a': 58, 'b': 22, 'c': 39}
Try Online

Program Output



In this Python Tutorial, we learned about the syntax and usage of Python Dictionary method dict.clear().