Python 字典 popitem() 方法,,描述Python 字
Python 字典 popitem() 方法,,描述Python 字
描述
Python 字典 popitem() 方法随机返回并删除字典中的一对键和值(一般删除末尾对)。
如果字典已经为空,却调用了此方法,就报出KeyError异常。
语法
popitem()方法语法:
dict.popitem()
参数
无返回值
返回一个键值对(key,value)形式。
实例
以下实例展示了 popitem() 方法的使用方法:
#!/usr/bin/python3site= {‘name‘: ‘菜鸟教程‘, ‘alexa‘: 10000, ‘url‘: ‘www.runoob.com‘}pop_obj=site.popitem()print(pop_obj) print(site)
输出结果为:
(‘url‘, ‘www.runoob.com‘){‘name‘: ‘菜鸟教程‘, ‘alexa‘: 10000}
Python 字典 popitem() 方法
相关内容
- Python str类的 find() 方法,,(str).find
- python环境tab命令自动补全,,在用户目录下创建.p
- Python编程练习(一),,学习中,都是从书上找
- python3 实现九九乘法表,,用python实现九
- 【python3】修饰器简单理解,,修饰器修饰器干嘛的,
- Python入门--18--异常与try,except语句,,Python标准异常
- python3之if语句,,获得更多资料欢迎进入
- Python库之虚拟现实,,Python库之虚拟
- python高性能编程--003--线程之Thread和threading,,一、线程
- python字典类型用法举例,,字典是python语
评论关闭