Optimization of Tuples and Strings
Carl Caulkett
carlca at dircon.co.uk
Mon Jan 7 02:47:51 EST 2002
In article <a1bik0$9b$1 at slb4.atl.mindspring.net>,
mgerrans at mindspring.com says...
> Anyone here know whether Python treats strings and tuples the way Java does
> Strings? That is, since they are immutable, does it just "point" multiple
> 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?
>>> x = (1,2)
>>> y = (1,2)
>>> id(x)
15769248
>>> id(y)
15793536
>>>
>>> a = '123'
>>> b = '123'
>>> id(a)
19919952
>>> id(b)
19919952
>>>
Tuples no, Strings yes, apparently. (using Python 2.2)
--
Cheers,
Carl
More information about the Python-list
mailing list