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'

你可能感兴趣的:(python)