在Python中操作字典之clear()方法的使用,pythonclear
在Python中操作字典之clear()方法的使用,pythonclear
clear()方法将删除字典中的所有项目(清空字典)
语法
以下是clear()方法的语法:
dict.clear()
参数
- NA
返回值
此方法不返回任何值。
例子
下面的例子显示了clear()方法的使用
#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7}; print "Start Len : %d" % len(dict) dict.clear() print "End Len : %d" % len(dict)
当我们运行上面的程序,它会产生以下结果:
Start Len : 2 End Len : 0
相关内容
- 浅谈Python中copy()方法的使用,pythoncopy
- 在Python中操作字典之fromkeys()方法的使用,pythonfromkeys
- 在Python中用get()方法获取字典键值的教程,pythonget
- 在Python中用has_key()方法查找键是否存在的教程,python
- Python中使用items()方法返回字典元素对的教程,pythonit
- 在Python中用keys()方法返回字典键的教程,pythonkeys
- 在Python中操作字典之setdefault()方法的使用,pythonsetdef
- python计算时间差的方法,python计算时间差
- 在Python中使用swapCase()方法转换大小写的教程,pythonsw
- python网络编程之数据传输UDP实例分析,pythonudp实例分析
评论关闭