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

查看所有标签

Language Implementation Patterns

Language Implementation Patterns

Terence Parr / Pragmatic Bookshelf / 2010-1-10 / USD 34.95

Knowing how to create domain-specific languages (DSLs) can give you a huge productivity boost. Instead of writing code in a general-purpose programming language, you can first build a custom language ......一起来看看 《Language Implementation Patterns》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具