working with pointers
Duncan Booth
duncan.booth at invalid.invalid
Wed Jun 1 10:02:32 EDT 2005
Leif K-Brooks wrote:
> Duncan Booth wrote:
>> The constant integers are created in advance, not when you do the
>> assignment.
>
> But that's just an optimization, not Python's defined behavior. It seems
> more useful to me to think of all integers as being created at
> assignment time, even if CPython doesn't actually do that.
>
Alternatively think of all integers as existing all of the time, whether or
not they are referenced.
Yes, it is just an optimisation, but it is one which results in an
observable difference in behaviour. i.e. if all integers are created as
they are needed you will never share integers.
Of course, if all integers existed all of the time then I guess you might
expect 'a==b' to always imply 'a is b', so my interpretation is differently
inaccurate.
More information about the Python-list
mailing list