Tuple slices
Steven Bethard
steven.bethard at gmail.com
Mon Jan 24 13:00:48 EST 2005
Fredrik Lundh wrote:
> George Sakkis wrote:
>
>>Why does slicing a tuple returns a new tuple instead of a view of the existing one, given that
>>tuples are immutable ?
>
> really?
>
>
>>>>a = 1, 2, 3
>>>>b = a[:]
>>>>a is b
> True
My impression was that full tuple copies didn't actually copy, but that
slicing a subset of a tuple might. Not exactly sure how to test this, but:
py> a = 1, 2, 3
py> a[:2] is a[:2]
False
So _something_ at least is different between the two slices...
Steve
More information about the Python-list
mailing list