Python3 Dictionary clear() Method
Description
The Python dictionary clear() function is used to delete all elements in the dictionary.
Syntax
clear() method syntax:
dict.clear()
Parameters
- NA。
Return Value
This function does not return any value.
Example
The following example demonstrates how to use the clear() function:
Example
#!/usr/bin/python3
tinydict = {'Name': 'Zara', 'Age': 7}
print ("Dictionary length : %d" % len(tinydict))
tinydict.clear()
print ("Dictionary length after deletion : %d" % len(tinydict))
tinydict = {'Name': 'Zara', 'Age': 7}
print ("Dictionary length : %d" % len(tinydict))
tinydict.clear()
print ("Dictionary length after deletion : %d" % len(tinydict))
The output of the above example is:
字典长度 : 2 字典删除后长度 : 0
Other Extensions
Python3 Dictionary