Python dictionary - clear() : method
Python Dictionary : clear()
- In order to remove the all items from the dictionary we use
clear()
. - It does not take any parameter
- Method does not return any value.
Syntax
Below syntax is used for clear()
method -
dict.clear()
Python Dictionary : clear() Example
#!/usr/bin/python dict = {'Word1': 'Meaning1', 'Word2': 'Meaning2'}; print ("Dictionary Length : %d" % len(dict)) dict.clear() print ("Dictionary Length : %d" % len(dict))
Output :
After running the program we will get below output -
>>> Dictionary Length : 2 Dictionary Length : 0 >>>