Python dictionary clear() Method
Advertisements
Description
The method clear() remove all items from the dictionary.
Syntax
Following is the syntax for clear() method
dict.clear()
Parameters
NA
Return Value
This method does not return any value.
Example
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)
Let us compile and run the above program, this will produce the following result:
Start Len : 2 End Len : 0