Optimization of Tuples and Strings
infinitystwin.SPAM at IS.BAD.yahoo.com
Mon Jan 7 03:38:21 EST 2002
"Matt Gerrans" <mgerrans at mindspring.com> wrote in message
news:a1bik0$9b$1 at slb4.atl.mindspring.net...
> Anyone here know whether Python treats strings and tuples the way Java
> Strings? That is, since they are immutable, does it just "point"
> references to an identical tuple to the same object? For example:
> x = (1,2)
> y = (1,2)
> Are x and y really referring to the same object?
> - Matt
>>> x = (1, 2)
>>> y = (1, 2)
>>> x = 2
>>> y = 2
>>> x = '1'
>>> y = '1'
I'm not sure about the extent of the this, though. I think Python keeps ints
up to a certain point (100?) around, because those numbers are common. But
the string thing suprised me; I only remember reading about integers.
More information about the Python-list