Python Dictionary clear() Method
Description
The Python Dictionary clear() function is used to delete all elements in the dictionary.
Syntax
The clear() method syntax is:
dict.clear()
Parameters
- NA。
Return Value
This function has no return value.
Example
The following example demonstrates how to use the clear() function:
Example
#!/usr/bin/python
tinydict = {'Name': 'Zara', 'Age': 7};
print "Start Len : %d" % len(tinydict)
tinydict.clear()
print "End Len : %d" % len(tinydict)
tinydict = {'Name': 'Zara', 'Age': 7};
print "Start Len : %d" % len(tinydict)
tinydict.clear()
print "End Len : %d" % len(tinydict)
The output of the above example is:
Start Len : 2 End Len : 0Other Extensions
Python Dictionary