Immutable and Mutable Types
Duncan Booth
duncan.booth at invalid.invalid
Mon Mar 17 06:02:23 EDT 2008
cokofreedom at gmail.com wrote:
>> >>> a = 1
>> >>> b = 1
>> >>> a is b
>> True
>> >>> id(a)
>> 10901000
>> >>> id(b)
>> 10901000
>
> Isn't this because integers up to a certain range are held in a single
> memory location, thus why they are the same?
>
Yes, in *some* implementations of Python this is exactly what happens. The
exact range, or indeed whether it happens at all, and (if it does happen)
whether the range depends on the phase of the moon are all undefined.
This, for example, is what I just got for a similar sequence:
>>> a = 1
>>> b = 5-4
>>> a is b
False
>>> id(a)
43L
>>> id(b)
44L
>>>
More information about the Python-list
mailing list