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'

 

相关文章:

  • 2021-12-07
  • 2021-07-19
  • 2022-01-27
  • 2022-12-23
  • 2021-04-15
  • 2022-12-23
猜你喜欢
  • 2021-06-19
  • 2021-07-14
  • 2021-09-21
  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
相关资源
相似解决方案