Legitimate use of the "is" comparison operator?

Mike Duffy Mike.S.Duffy at gmail.com
Sat Jun 17 04:42:13 EDT 2006


Gary Herron wrote:
>
> >>> 100 is (99+1)
> False
>
> >>> 2 is (1+1)
> True
>
> >>> 100 is 100
> True
>
> This is highly implementation dependent. The current (C) implementation
> of Python has a cache for small integers, so the attempt to compare
> values with "is" works for some small integers, and fails for some large
> integers, but curiously, not all instances of comparing large integers.
>

Ahh, thank you. That explains why Fredrick's and Jean-Paul's example
did not work, but mine did (I was using *small* integers). Ok, well I
definitely get the picture. Use the "is" operator for what it was
intended for, or deal with broken code ;-)  Thanks a lot guys.




More information about the Python-list mailing list