Re: Result of ``a is b''
Andrew Koenig wrote:[color=blue]
>
>
> "Axel Boldt" <axelboldt@yaho o.com> wrote in message
> news:40200384.0 403161255.7fca7 a8c@posting.goo gle.com...
>[color=green]
>> Wow. So it seems that the action of "is" on immutables is unspecified
>> and implementation dependent, thus useless to the programmer.[/color]
>
> 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.[/color]
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.[color=blue][color=green][color=darkred]
>>> class a:[/color][/color][/color]
.... def __eq__(x,y): return 0
....[color=blue][color=green][color=darkred]
>>> b = a()
>>> b is b[/color][/color][/color]
1[color=blue][color=green][color=darkred]
>>> b == b[/color][/color][/color]
0
So I don't think we can call it a "fundamenta l property" (unless the
language has changed, which actually wouldn't surprise me).
--
CARL BANKS http://www.aerojockey.com/software
"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
Andrew Koenig wrote:[color=blue]
>
>
> "Axel Boldt" <axelboldt@yaho o.com> wrote in message
> news:40200384.0 403161255.7fca7 a8c@posting.goo gle.com...
>[color=green]
>> Wow. So it seems that the action of "is" on immutables is unspecified
>> and implementation dependent, thus useless to the programmer.[/color]
>
> 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.[/color]
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.[color=blue][color=green][color=darkred]
>>> class a:[/color][/color][/color]
.... def __eq__(x,y): return 0
....[color=blue][color=green][color=darkred]
>>> b = a()
>>> b is b[/color][/color][/color]
1[color=blue][color=green][color=darkred]
>>> b == b[/color][/color][/color]
0
So I don't think we can call it a "fundamenta l property" (unless the
language has changed, which actually wouldn't surprise me).
--
CARL BANKS http://www.aerojockey.com/software
"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
Comment