Python Tutorial Python Advanced Python References Python Libraries

Python Dictionary - clear() Method



The Python clear() method is used to delete all key-value pairs present in the dictionary.

Syntax

dictionary.clear()

Parameters

No parameter is required.

Return Value

None.

Example:

In the example below, the clear() method is used to delete all elements of the dictionary called Info.

Info = {
  'name': 'John',
  'age': 25,
  'city': 'London'
}
#delete all elements from 'Info' dictionary.
Info.clear()

print(Info)

The output of the above code will be:

{}

❮ Python Dictionary Methods