Python Dictionary clear() Method
The clear()
method removes all items (key-value pairs) from a dictionary, making it empty. It is useful for resetting or clearing a dictionary’s content.
Syntax
dictionary.clear()
Parameters
It doesn’t take any parameters
Return Value
It doesn’t return any value (returns None
)
Example:
person = {"name": "James Bond", "age": 37, "city": "London"}
person.clear()
print(person) # Output: {}
The clear()
method doesn’t delete the dictionary; it only removes its contents.