'==' vs. 'is' behavior

Aahz Maruch aahz at netcom.com
Mon Nov 29 18:46:02 EST 1999


In article <oqemd9dk2g.fsf at titan.progiciels-bpi.ca>,
=?ISO-8859-1?Q?Fran=E7ois_Pinard?=  <pinard at iro.umontreal.ca> wrote:
>
>By the way, is there common wisdom (or rather, maybe, usage-standards-to-be)
>about using `is' instead of `=='?

"is" is faster, but you should use == unless you know for sure you want
to test object equality instead of value equality.  For example:

x = 'abc'
if x is 'abc' :
  ...

may or may not fail, depending on how python handles object creation;
OTOH, it's almost certain that the following will fail:

x = raw_input()
if x is 'abc' :
  ...
--
                      --- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Question authority: ask me anything!




More information about the Python-list mailing list