[Tutor] Variables and constants [was Re: working with strings inpython3]
Steven D'Aprano
steve at pearwood.info
Wed Apr 20 00:30:09 CEST 2011
bodsda at googlemail.com wrote:
> And presumably cleans up the leftover object with the value of 42 when it changes to point at the 43 object?
In principle, yes, the garbage collector will destroy the no-longer used
object 42 once nothing is pointing to it any more.
But in practice, Python caches "small integers", where the definition of
small depends on which version of Python you are using, on the basis
that it's better to hang onto them in a cache for re-use than to keep
making and destroying them over and over again. This is a classic "time
versus space" trade-off: using extra memory to save time.
--
Steven
More information about the Tutor
mailing list