2011/3/19 Yaşar Arabacı <yasar11...@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
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor