Python语言基础
Python语言进阶
Python数据结构

Python dictionary pop() 方法

搞懂Python dictionary pop() 方法的用法

描述

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

语法

pop()方法语法:
pop(key[,default])

参数

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

返回值

返回被删除的值。

实例

以下实例展示了 pop() 方法的使用方法:
>>> site= {'name': 'lidihuo', 'url': 'www.lidihuo.com'}
>>> pop_obj=site.pop('name')
>>> print(pop_obj)
lidihuo
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4