Python dictionary method clear() eliminates entire articles from the dictionary. Clear() clears the similar dictionary that d and d2 together point at. d = {} will generate a new example for d excluding entire additional references will immobile point to the aged contents. ... clear() will rearrange the contents, however, all orientations to the identical example will still be right.
Following is the syntax for the clear() method:
dict.clear()
This method does not return any value.
The following example shows the usage of the 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 the above program, it produces the following result:
Start Len : 2 End Len : 0
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.