Clear method- Remove All Items from a Dictionary in Python

Spread the love

Clear Method –

The clear() method removes all items from a dictionary.

Syntax of clear –


Let’s say we have dictionary which contains information of a person.

In [1]: person = {'Name':'Noah', 'Age': 25, 'Location': 'New York'}

Now, to remove all the key-value pairs of the dictionary we can use the clear method.

In [2]: person.clear()

In [3]: person
Out[3]: {}

Rating: 1 out of 5.

Leave a Reply