In the example you gave, there is no difference, in terms of output, between append
and +=
. But there is a difference between append
and +
(which the question originally asked about).
>>> a = []
>>> id(a)
11814312
>>> a.append("hello")
>>> id(a)
11814312
>>> b = []
>>> id(b)
11828720
>>> c = b + ["hello"]
>>> id(c)
11833752
>>> b += ["hello"]
>>> id(b)
11828720
As you can see, append
and +=
have the same result; they add the item to the list, without producing a new list. Using +
adds the two lists and produces a new list.