'dict' object has no attribute 'has_key'

后端 未结 6 985
太阳男子
太阳男子 2021-01-30 03:46

While traversing a graph in Python, a I\'m receiving this error:

\'dict\' object has no attribute \'has_key\'

Here is my code:

6条回答
  •  孤街浪徒
    2021-01-30 04:07

    In python3, has_key(key) is replaced by __contains__(key)

    Tested in python3.7:

    a = {'a':1, 'b':2, 'c':3}
    print(a.__contains__('a'))
    

提交回复
热议问题