Python3 字典 pop() 方法

Python 3 教程 · 2019-02-06 17:27:46

描述

Python 字典 pop() 方法删除字典给定键 key 所对应的值,返回值为被删除的值。key值必须给出。 否则,返回default值。

语法

pop()方法语法:

pop(key[,default])

参数

  • key: 要删除的键值
  • default: 如果没有 key,返回 default 值

返回值

返回被删除的值。

实例

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

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

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

查看所有标签

Dreamweaver CS3 Bible

Dreamweaver CS3 Bible

Joseph W. Lowery / Wiley / May 21, 2007 / $49.99

Book Description Learn to create dynamic, data-driven Web sites using the exciting enhancements in the Dreamweaver CS3 version. You get a thorough understanding of the basics and then progress to l......一起来看看 《Dreamweaver CS3 Bible》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具