[Tutor] Need some clarification on this
Emmanuel Ruellan
emmanuel.ruellan at laposte.net
Sat Mar 19 16:35:16 CET 2011
2011/3/19 Yaşar Arabacı <yasar11732 at gmail.com>
>
>
> >>>a=5
> >>>b=5
> >>>a == b
> True
> >>>a is b
> True
>
> My question is, why "a is b" is true. What I expected it to be is that, a
> and b are different things with same value.
>
Even stranger:
>>> a = 10**10
>>> b = 10**10
>>> a == b
True
>>> a is b
False
>>> a = 5
>>> b = 5
>>> a == b
True
>>> a is b
True
In the general case, you're right: a and b point to two different objects,
but there is also some kind of optimisation for small numbers, and as a
result when a = 5 and b = 5, both point the same '5' object.
Emmanuel Ruellan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110319/18e6eb73/attachment.html>
More information about the Tutor
mailing list