python中字典dict pop方法

首先引用下pythondoc

pop(key[, default])
If key is in the dictionary, remove it and return its value, else return default. If default is not given and key is not in the dictionary, a KeyError is raised.

然后是例子

default = dic(a='a', b='b', c='c')
k = default.pop(a) # k='a'
k = default.pop(b, 'sss') # k='b'
k = default.pop(d) # Error
k = default.pop(n, 'sss') # k='sss'
posted @ 2015-05-26 17:07  Bluethon  阅读(1998)  评论(0编辑  收藏  举报