From: Terry Reedy on
On 5/3/2010 12:37 AM, Alf P. Steinbach wrote:
> * Terry Reedy:
>> * Alf P. Steinbach:
>>> * Aahz:
>>
>>>> and sometimes
>>>> they rebind the original target to the same object.
>>>
>>> At the Python level that seems to be an undetectable null-operation.
>>
>> If you try t=(1,2,3); t[1]+=3, if very much matters that a rebind occurs.
>
> Testing:
>
> <test lang="py3">
> >>> t = ([], [], [])
> >>> t
> ([], [], [])
> >>> t[0] += ["blah"]
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: 'tuple' object does not support item assignment
> >>> t
> (['blah'], [], [])
> >>> _
> </test>
>
> Yep, it matters.

So one should instead write t[0].extend('blah') to the same effect, but
without the exception raising assignment attempt, when that is what one
really means ;-).

Terry Jan Reedy