Python dictionary clear() method
Python Dictionary clear() Method
Description
The Python dictionary method clear() removes all items from a dictionary.
Syntax
Below is the syntax of the clear() method.
dict.clear()
Parameters
None
Return Value
This method does not return any value.
Example
The following example demonstrates the usage of the clear() method.
dict = {'Name': 'Zara', 'Age': 7};
print ("Start Len : %d" % len(dict))
dict.clear()
print ("End Len : %d" % len(dict))
When we run the above program, it produces the following output.
Start Len : 2
End Len : 0