字典删除方法:pop()和popitem(),这两种种方法的作用不同,操作方法及返回值都不相同。
pop (key[,default])

其中,key是必选参数,必须给出,default是可选参数,可以不给出。
如果键值key在字典中存在,删除dict[key],返回 dict[key]的value值。
否则,如有给出default值则返回default值,如果default值没有给出,就会报出KeyError异常。
pop()方法至少接受一个参数,最多接受两个参数。
1.仅给出key且key在字典中 或 key和default都给出且key在字典中

site= {'name': '菜鸟教程', 'alexa': 10000, 'url': 'www.runoob.com'}
pop_obj=site.pop('name')
print (pop_obj)    # 输出 :菜鸟教程

  

site= {'name': '菜鸟教程', 'alexa': 10000, 'url': 'www.runoob.com'}
pop_obj=site.pop('method',None)
print (pop_obj)    # 输出 :None

2.仅给出key且key不在字典中

site= {'name': '菜鸟教程', 'alexa': 10000, 'url': 'www.runoob.com'}
pop_obj=site.pop('method')
print (pop_obj)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-27-4f7229078c3c> in <module>()
      1 site= {'name': '菜鸟教程', 'alexa': 10000, 'url': 'www.runoob.com'}
----> 2 pop_obj=site.pop('method')
      3 print (pop_obj)    # 输出 :None

KeyError: 'method'

popitem()
随机删除字典中的一个键值对,并且返回该键值对,(key,value)形式。
如果字典已经为空,却调用了此方法,就报出KeyError异常。

site= {'name': '菜鸟教程', 'alexa': 10000, 'url': 'www.runoob.com'}
pop_obj=site.popitem()
print (pop_obj)  
返回元组(key,values)