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://codercto.com/courses/l/10.html
Head First Python
Paul Barry / O'Reilly Media / 2010-11-30 / USD 49.99
Are you keen to add Python to your programming skills? Learn quickly and have some fun at the same time with Head First Python. This book takes you beyond typical how-to manuals with engaging images, ......一起来看看 《Head First Python》 这本书的介绍吧!