dictionary

>>> a = {"1":"WuWei"}
>>> name = a.pop('2', [])
>>> name
[]
>>> name = a.pop('2')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: '2'
>>> name = a.pop('1')
>>> name
'WuWei'
>>> a
{}

pop(...)
    D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
    If key is not found, d is returned if given, otherwise KeyError is raised


发布了82 篇原创文章 · 获赞 46 · 访问量 96万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章