If a
is a list, a + x
only works if x
is also list, whereas a += x
works for any iterable x
.
The following might help understand it:
In [4]: a = []
In [5]: a += "abc"
In [6]: a
Out[6]: ['a', 'b', 'c']
The key is that "a"
and "abc"
are iterable, which is what enables their use on the right-hand side of +=
.
This doesn't work for +
because the latter requires both operands to be of the same type (see the manual).
To write the same thing using +
, you have to expand the iterable:
In [7]: a = []
In [8]: a = a + list("abc")
In [9]: a
Out[9]: ['a', 'b', 'c']
In other words, +=
is more general than +
when applied to lists.