Python3 Dictionary clear () method
description
Python dictionary clear () function deletes all the elements in the dictionary.
grammar
clear () method syntax:
dict.clear()
parameter
- NA.
return value
This function has no return value.
Examples
The following example shows the clear () function to use:
#!/usr/bin/python3 dict = {'Name': 'Zara', 'Age': 7} print ("字典长度 : %d" % len(dict)) dict.clear() print ("字典删除后长度 : %d" % len(dict))
The above example output is:
字典长度 : 2 字典删除后长度 : 0