How to Delete All Items in Dictionary Using Python clear()

Last Updated on December 25, 2020 by Roshan Parihar

In this tutorial, learn how to delete all items in Dictionary using Python. The short answer is: use Python clear() function to delete all keys items of Dictionary.

Likewise, removing single or deleting multiple elements of Dictionary in Python, you may be want to clear all the elements of Dictionary. For that reason, you can use the Python method called clear() function.

How to Delete All Items in Dictionary Using Python clear()

How to Delete All Items in Dictionary Using Python clear()

The clear() function in Python requires no argument to delete all keys elements of Dictionary. You can use the below example to perform this task.

Output

{}

Finally, the output showing in the example above shows that there are no elements remain in myDict Dictionary. You will get only the curly({}) brackets in the output as a result of clear().

You May Also Like to Read