This is a special feature called interning in python. As of Python 2.6, values of -5 to 105 are never cleared from memory for performance reasons. This is applicable to integers only.
"==" is a value comparator, whereas "is" is a reference compartor. Check this interesting extension to your code: >>> a=5.0 >>> b=5.0 >>> a==b True >>> a is b False Because I used "5.0" instead of "5", the "is" operator is giving a different result ("False") ~ Ajit Deshpande 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. > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor