is and ==

Aahz Maruch aahz at panix.com
Mon Feb 26 17:45:30 CET 2001


In article <movk9t0una5nuca6upgk9rcco96fbkeu51 at 4ax.com>,
Daniel Klein  <danielk at aracnet.com> wrote:
>
>Is there a functional difference between 'is' and '==' ?  If there is, I can't
>find it.

>>> a = 'xy'
>>> b = a
>>> c = 'x' + 'y'
>>> d = 'xy'
>>> a is b
1
>>> a is d
1
>>> a is c
0
>>> a == c
1

Essentially, is tests for object identity: are two variables pointing to
the same location in memory.  == tests to see whether the *values* are
equal.
-- 
                      --- Aahz (Copyright 2001 by aahz at pobox.com)

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

"I used to have a .sig but I found it impossible to please everyone..."  --SFJ



More information about the Python-list mailing list