当前第2页 返回上一页
1 2 3 4 5 | >>> x = { 'a' :1, 'b' :2}
>>> x.pop( 'a' )
1
>>> x
{ 'b' : 2}
|
3、字典popitem()方法作用是:随机返回并删除字典中的一对键和值(项)。
1 2 3 4 5 6 | >>> x
{ 'url' : 'www.iplaypy.com' , 'title' : 'python web site' }
>>> x.popitem()
( 'url' , 'www.iplaypy.com' )
>>> x
{ 'title' : 'python web site' }
|
4、del方法能删单一的元素也能清空字典,清空只需一项操作。
1 2 3 4 5 | #!/usr/bin/python
# -*- coding: UTF-8 -*-
dict = { 'Name' : 'Zara' , 'Age' : 7, 'Class' : 'First' }
del dict[ 'Name' ] # 删除键是 'Name' 的条目
del dict # 删除字典
|
更多Python相关技术文章,请访问Python教程栏目进行学习!
以上就是python字典中怎么删除元素的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
电脑64位怎么下载Python
Python列表的基本操作有哪些
spyder和Python的关系是什么
Python正则表达式中re模块的使用方法有哪些?re模块用法介绍
Python单词怎么读
成为Python大牛必不可少的几款编辑器
hash()是Python内置的吗
在Python中复数怎么表示
Python线程下thread对象的用法介绍(附实例)
如何用爬虫破解滑动验证码
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python字典中怎么删除元素