Python 3.x不再支持 has_key() 函数,而被__contains__('key')所替代,会返回bool,可以用其做判断。
代码示例:
>>> user = 'dadada'
>>> db = {'dadada':'123545','fff':'111111','ffasafs':'hhh'}
>>> db.__contains__(user)
True
>>> user = 'dadad1a'
>>> db.__contains__(user)
False
转载于:https://www.cnblogs.com/Demo-simple/p/11065530.html