Why does this
l = [1,2,3]
l += 4,5,6
work, while this
l = [1,2,3] + (4,)
does not?
If I try the second one, I get a TypeError: can only concatenate list (not "tuple") to list
, which makes sense.
But the first version should do about the same. In the second line the 4,5,6
should create a tuple, as seen in this example:
>>> t = 4,5,6
>>> type(t)
<type 'tuple'>
And after creating the tuple, += should just add to the list l
. So also here it should throw some kind of error, but it does not.
Does anyone know what is happening here?
This behaviour is consistent between Python 2.7.11 and Python 3.5.1.