Python 字典 pop() 方法

Python 教程 · 2019-02-03 09:14:18

描述

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

语法

pop()方法语法:

pop(key[,default])

参数

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

返回值

返回被删除的值。

实例

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

#!/usr/bin/python
# -*- coding: UTF-8 -*-

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

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

查看所有标签

Programming the Mobile Web

Programming the Mobile Web

Maximiliano Firtman / O'Reilly Media / 2010-07-23 / $44.99

* Learn how to use your existing skills to move into mobile web development * Discover the new possibilities of mobile web development, and understand its limitations * Get detailed coverage of ......一起来看看 《Programming the Mobile Web》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

MD5 加密
MD5 加密

MD5 加密工具