1 >>> a={1:‘a‘,2:‘b‘} 2 >>> 1 in a 3 True 4 >>> ‘a‘ in a 5 False 6 >>> 2 in a 7 True 8 >>>
即可以判断某个键是否存在于字典中;
1 >>> a.has_key(1) 2 Traceback (most recent call last): 3 File "<pyshell#27>", line 1, in <module> 4 a.has_key(1) 5 AttributeError: ‘dict‘ object has no attribute ‘has_key‘
时间: 2024-10-11 07:34:03