The method clear() removes all items from the dictionary.
Following is the syntax for clear() method:
dict.clear()
NA
This method does not return any value.
The following example shows the usage of clear() method.
#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7}; print "Start Len : %d" % len(dict) dict.clear() print "End Len : %d" % len(dict)
When we run above program, it produces following result:
Start Len : 2 End Len : 0