字典Dict 判断指定键值是否存在

初始化数组

>>> temp = {}
>>> temp['test'] = 't1'
>>> temp['test2'] = 2
>>> temp
{'test': 't1', 'test2': 2}
一。通过字典对象的方法 has_key 判断
>>> temp.has_key('test')
True
>>> temp.has_key('test1')
False
二。通过 in keys()的方法
>>> 'test2' in temp.keys()
True
>>> 'test1' in temp.keys()
False
    原文作者:Jiacch
    原文地址: https://www.jianshu.com/p/b430b223972a
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞