TypeError expected in an augmented assignment

Terry Reedy tjreedy at udel.edu
Thu Jul 3 04:57:49 CEST 2014


On 7/2/2014 10:39 PM, candide wrote:
> An hybrid list-tuple concatenation is not allowed
>
>>>> []+(1, 2)
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: can only concatenate list (not "tuple") to list
>>>>
>
>
>
> hence I was expecting (*) that the following code raises a TypeError :
>
>>>> x = []
>>>> x += (1, 2)
>>>> x
> [1, 2]
>>>>
>
>
> Any explanation ?
 >>> seq = [1,2]
 >>> seq.extend((3,4))
 >>> seq+= {5, 6}  # the order of extending is not determined
 >>> seq
[1, 2, 3, 4, 5, 6]
 >>>

-- 
Terry Jan Reedy




More information about the Python-list mailing list