The +=
in-place add operator on a list does the same thing as calling list.extend() on new_list
. .extend()
takes an iterable and adds each and every element to the list.
list.append()
on the other hand, adds a single item to the list.
>>> lst = []
>>> lst.extend([1, 2, 3])
>>> lst
[1, 2, 3]
>>> lst.append([1, 2, 3])
>>> lst
[1, 2, 3, [1, 2, 3]]