Python Frequently Asked Questions, Release 3.9.5 25 2.5. Sequences (Tuples/Lists) This is equivalent to: To see why this happens, you need to know that (a) if an object implements an$_{__iadd__}$ magic method, it gets called when the += augmented assignment is executed, and its return value is what gets used in the assignment statement; and (b) for lists,$_{__iadd__}$ is equivalent to calling$_{extend}$on the list and returning the list. That’s why we say that for lists,$_{+=}$ is a “shorthand” for$_{list.extend}$ : The exception is a bit more surprising, and even more surprising is the fact that even though there was an error, the append worked: It is the assignment part of the operation that produces the error, since a tuple is immutable. When you write something like: The reason for the exception should be immediately clear: $_{1}$is added to the object$_{a_tuple[0]}$ points to ($_{1}$ ), producing the result object,$_{2}$ , but when we attempt to assign the result of the computation,$_{2}$ , to element$_{0}$of the tuple, we get an error because we can’t change what an element of a tuple points to. Under the covers, what this augmented assignment statement is doing is approximately this: This is because of a combination of the fact that augmented assignment operators are assignment operators, and the difference between mutable and immutable objects in Python. This discussion applies in general when augmented assignment operators are applied to elements of a tuple that point to mutable objects, but we’ll use a list and += as our exemplar. If you wrote: Use a list comprehension: 2.5.8 How do I apply a method to a sequence of objects? 2.5.9 Why does a_tuple[i] += [‘item’] raise an exception when the addition works? >>> a_list=[] >>> a_list+=[1] >>> a_list [1] >>> a_tuple=(['foo'],'bar') >>> a_tuple[ 0] +=['item'] Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment >>> result=a_tuple[ 0] +1 >>> a_tuple[ 0] =result Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment >>> a_tuple=(1,2) >>> a_tuple[ 0] +=1 Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment result=[obj.method() for obj in mylist] >>> a_tuple[ 0] ['foo', 'item']