4.2.13Python下字典的dict.pop方法
Posted by 撒得一地 on 2016年2月22日 in python教程
pop()方法语法:
dict.pop(键名)
描述
pop()方法用来获得对应给定键的值,然后将这个键-值对从字典中移除。
pop()方法要带上键名参数,否则会出错。
具体实例:
>>> d = {'url':'coderschool.cn','title':'psz'}
>>> d
{'title': 'psz', 'url': 'coderschool.cn'}
>>> d.pop()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: pop expected at least 1 arguments, got 0
>>> d.pop('title')
'psz'
>>> d
{'url': 'coderschool.cn'}