Immutable and Mutable Types
Diez B. Roggisch
deets at nospam.web.de
Mon Mar 17 11:09:27 CET 2008
cokofreedom at gmail.com wrote:
>> >>> a = 1
>> >>> b = 1
>> >>> a is b
>> >>> id(a)
>> >>> id(b)
> Isn't this because integers up to a certain range are held in a single
> memory location, thus why they are the same?
As the OP said:
Depending on implementation, for immutable types, operations that compute
new values may or may not actually return a reference to any existing object
with the same type and value, while for mutable objects this is (strictly)?
Which is exactly what happens - the actual implementation chose to cache
some values based on heuristics or common sense - but no guarantees are
made in either way.
More information about the Python-list