>>> b = []
>>> c = '1234'
>>> b += c
>>> b
['1', '2', '3', '4']
>>>
What is happening here? This should not work, right? Or am I missing something obvious?
>>> b = []
>>> c = '1234'
>>> b + c
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
b + c
TypeError: can only concatenate list (not "str") to list
>>>
Then a += b is not always equivalent to a = a + b ?
A string is a sequence of characters. The list operation
+=takes any sequence and appends each of the sequence's elements to the list.(Actually
+=takes any iterable.)