different binding behavior

Steven D'Aprano steve at REMOVETHIScyber.com.au
Fri Nov 18 22:42:58 EST 2005


On Fri, 18 Nov 2005 15:34:36 +0100, Gabriel Zachmann wrote:

> i don't see why there should be only one instance of Int with the value 0.

"Small" ints are cached, so there may be only one instance of the int with
value 0. However, that's an implementation detail, which may change from
version to version, and is not generally true:

py> x = 0; y = 3-3
py> x == y
True
py> x is y
True

py> x = 357900001; y = 3579*100000+1
py> x == y
True
py> x is y
False

So in general, there can be many instances of int with the same value.
That's not what immutable means.



-- 
Steven.




More information about the Python-list mailing list