First of all, it is important to note here that in this case a += 1, works differently than a = a + 1, ,. ( a = a + 1, and a = a + (1,) throw a TypeError because you cannot concatenate the list and tuple, but you can expand the list with a tuple.)
+= calls the __iadd__ list, which calls list.extend , and then returns the original list.
1, is a tuple of length one, so what do you do
>>> a = [] >>> a.extend((1,)) >>> a [1]
which looks just weird because of the length of one tuple. But it works the same as expanding a list with a tuple of any length:
>>> a.extend((2,3,4)) >>> a [1, 2, 3, 4]
source share