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

Ben Finney bignose+hates-spam at benfinney.id.au
Thu Oct 30 20:08:04 EDT 2008


Łukasz Ligowski <orangewarrior at gmail.com> writes:

> 2.5 docs say that:
>  "a.has_key(k) Equivalent to k in a, use that form in new code"
> 
> 2.6 docs say that:
>  "dict.has_key(key) is equivalent to key in d, but deprecated."
> 
> which is true?

Both are true, and are different ways of saying the same thing.

     ‘a.has_key(k)’ is deprecated, use ‘k in a’ in new code.

You might be confused by the ambiguous referent for “that form” in
the passage from the 2.5 docs. The meaning is made more clear in the
passage you quote from the 2.6 docs.

-- 
 \       “The most common of all follies is to believe passionately in |
  `\    the palpably not true. It is the chief occupation of mankind.” |
_o__)                                                —Henry L. Mencken |
Ben Finney



More information about the Python-list mailing list