Difference between + and + = with python lists

I played a little with python lists, and I find the following a bit strange.

list = ["test"]
list + "test1" 
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "str") to list

list += "test1"
print(list)
['test', 't', 'e', 's', 't', '1']

Can someone help me understand why + = works, but + doesn't?

In addition, I was expecting "test1" to be added as a single item. Why is one element per letter?

+6
source share

All Articles