"xxx.has_key(a)" vs "a in xxx"

Kurt Smith kwmsmith at gmail.com
Thu Oct 30 15:50:57 CET 2008


On Thu, Oct 30, 2008 at 9:37 AM, Łukasz Ligowski <orangewarrior at gmail.com>wrote:

> Hi,
>
> There is small inconsistency (or I don't understand it right) between
> python
> 2.5 docs and python 2.6 docs.
>
> 2.5 docs say that:
>  "a.has_key(k) Equivalent to k in a, use that form in new code"


Meaning: don't use 'a.has_key(k)'.


>
>
> 2.6 docs say that:
>  "dict.has_key(key) is equivalent to key in d, but deprecated."


Meaning, 'd.has_key(key)' is deprecated -- use 'key in d'.


>
>
> which is true?


Both.

[269]$ python2.6 -3
Python 2.6 (r26:66714, Oct  2 2008, 12:46:52)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> D = {'foo':'bar'}
>>> 'foo' in D
True
>>> D.has_key('foo')
__main__:1: DeprecationWarning: dict.has_key() not supported in 3.x; use the
in operator
True
>>>



>
>
> L
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081030/da469704/attachment.html>


More information about the Python-list mailing list