Result of ``a is b''

Carl Banks imbosol at aerojockey.invalid
Wed Mar 17 03:42:47 CET 2004

Andrew Koenig wrote:
> "Axel Boldt" <axelboldt at> wrote in message
> news:40200384.0403161255.7fca7a8c at
>> Wow. So it seems that the action of "is" on immutables is unspecified
>> and implementation dependent, thus useless to the programmer.
> Hardly.  It has two fundamental properties, which can sometimes be useful:
>    1) If x and y refer to the same object, "x is y" yields True.
>    2) If "x is y" yields True, "x==y" also yields True.  Equivalently, if
> "x==y" yields False, "x is y" also yields False.

Python 2.2.3c1 (#12, May 27 2003, 21:32:04) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class a:  
...     def __eq__(x,y): return 0
>>> b = a()
>>> b is b
>>> b == b

So I don't think we can call it a "fundamental property" (unless the
language has changed, which actually wouldn't surprise me).

CARL BANKS            
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon

More information about the Python-list mailing list