Python中字典的has_key方法在3.4版本中改为in

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'

 

posted @ 2014-12-11 11:56  志者之梦  阅读(1102)  评论(0编辑  收藏  举报