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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章