Python3 字典 popitem() 方法

Python 3 教程 · 2019-02-06 17:44:18

描述

Python 字典 popitem() 方法随机返回并删除字典中的一对键和值(一般删除末尾对)。

如果字典已经为空,却调用了此方法,就报出KeyError异常。

语法

popitem()方法语法:

popitem()

参数

返回值

返回一个键值对(key,value)形式。

实例

以下实例展示了 popitem() 方法的使用方法:

#!/usr/bin/python3

site= {'name': '码农教程', 'alexa': 10000, 'url': 'www.codercto.com'}
pop_obj=site.popitem()
print(pop_obj)   
print(site)

输出结果为:

('url', 'www.codercto.com')
{'name': '码农教程', 'alexa': 10000}

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Web Standards Creativity

Web Standards Creativity

Andy Budd、Dan Rubin、Jeff Croft、Cameron Adams、Ethan Marcotte、Andy Clarke、Ian Lloyd、Mark Boulton、Rob Weychert、Simon Collison、Derek Featherstone / friends of ED / March 19, 2007 / $49.99

Book Description * Be inspired by 10 web design lessons from 10 of the world's best web designers * Get creative with cutting-edge XHTML, CSS, and DOM scripting techniques * Learn breathtakin......一起来看看 《Web Standards Creativity》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试