Interesting behaviour of the assignment

Moshe Zadka moshez at zadka.site.co.il
Thu Dec 28 16:54:41 CET 2000


On Thu, 28 Dec 2000, "June Kim" <junaftnoon at nospamplzyahoo.com> wrote:

> >>> a=100
> >>> b=100
> >>> a is b
> 0
> >>> a=99
> >>> b=99
> >>> a is b
> 1
> 
> Is this an intended/expected result? What is the lying structure beneath
> this?

The Python implementation makes no promises of the identity of 
immutable data types which are ==.
In other words, if "a==b", and both a and b are of the same immutable
data type (e.g., strings, integers or tuples) then it might or might
not be the case that "a is b". 

This allows the implementation to do all sorts of nifty optimizations.




More information about the Python-list mailing list