美文网首页
dict' object has no attribut

dict' object has no attribut

作者: 腿长袖子短 | 来源:发表于2017-12-22 09:30 被阅读290次
    • 在python2中对于一个dict,可以用dict.has_key(key_name)检测键是否存在
      在python3中这样使用会报错AttributeError: 'dict' object has no attribute 'has_key'

    • python3 用法:

    words = {'a':1, 'b':2 , 'c':3}
    'a' in words 
    
    • key存在返回True
      key不存在返回False

    相关文章

      网友评论

          本文标题:dict' object has no attribut

          本文链接:https://www.haomeiwen.com/subject/jthtgxtx.html