[Tutor] Need some clarification on this

Ajit Deshpande ajitsd at gmail.com
Sat Mar 19 18:18:38 CET 2011

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
>>> a is b

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ı <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.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110319/d2282d44/attachment.html>

More information about the Tutor mailing list