这篇文章主要介绍了在Python中操作字典之clear()方法的使用,是Python入门的基础知识,需要的朋友可以参考下
clear()方法将删除字典中的所有项目(清空字典)
语法
以下是clear()方法的语法:
?
1 dict.clear()参数
NA
返回值
此方法不返回任何值。
例子
下面的例子显示了clear()方法的使用
?
1 2 3 4 5 6 7 #!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7}; print "Start Len : %d" % len(dict) dict.clear() print "End Len : %d" % len(dict)当我们运行上面的程序,它会产生以下结果:
?
1 2 Start Len : 2 End Len : 0