>>> x = ['a', 'b']
>>> x
['a', 'b']
>>> x += 'c'
>>> x
['a', 'b', 'c']
>>> x += ''
>>> x
['a', 'b', 'c']
>>> x += ['']
>>> x
['a', 'b', 'c', '']

you might want to add:

>>> x += 'foo'
>>> x
['a', 'b', 'c', '', 'f', 'o', 'o']

and maybe

>>> x.append('foo')
>>> x
['a', 'b', 'c', '', 'f', 'o', 'o', 'foo']
Comment by Anonymous Qui 02 Fev 2012 13:50:04 UTC

you might want to add:

>>> x += 'foo'
>>> x
['a', 'b', 'c', '', 'f', 'o', 'o']

and maybe

>>> x.append('foo')
>>> x
['a', 'b', 'c', '', 'f', 'o', 'o', 'foo']
Comment by Anonymous Qui 02 Fev 2012 13:50:20 UTC

you might want to add:

>>> x += 'foo'
>>> x
['a', 'b', 'c', '', 'f', 'o', 'o']

and maybe

>>> x.append('foo')
>>> x
['a', 'b', 'c', '', 'f', 'o', 'o', 'foo']
Comment by Anonymous Qui 02 Fev 2012 13:52:18 UTC

you might want to add:

x += 'foo' x ['a', 'b', 'c', '', 'f', 'o', 'o']

and maybe

x.append('foo') x ['a', 'b', 'c', '', 'f', 'o', 'o', 'foo']

Comment by Marco Túlio Qui 02 Fev 2012 14:08:13 UTC

you might want to add:

x += 'foo' x ['a', 'b', 'c', '', 'f', 'o', 'o']

and maybe

x.append('foo') x ['a', 'b', 'c', '', 'f', 'o', 'o', 'foo']

Comment by Marco Túlio Qui 02 Fev 2012 14:08:21 UTC

you might want to add:

x += 'foo' x ['a', 'b', 'c', '', 'f', 'o', 'o']

and maybe

x.append('foo') x ['a', 'b', 'c', '', 'f', 'o', 'o', 'foo']

Comment by Marco Túlio Qui 02 Fev 2012 14:09:15 UTC

It seems that for a list x, the statement:

x += y
is internally translated into:
for elem in y:
   x.append(elem)

Whereas for a list x, the statement

x + y
requires y to be a list.

Python can iterate over a string, it's individual characters.

x = ["a", "b"]
x += "cd"
   => x becomes ["a", "b", "c", "d"]
x = ["a", "b"]  
x = x + "cd"  
   => ERROR: can only concatenate list (not "str") to list  

The same difference we see with sets:

x = ["a", "b"]  
x += set(["c", "d"])  
   => x becomes ["a", "b", "c", "d"]  
x = ["a", "b"]  
x = x + set(["c", "d"])  
   => ERROR: can only concatenate list (not "str") to list  

Also, since a string is not iterable, this does not work:

x = ["a", "b"]  
x += 1  
   => ERROR: 'int' object is not iterable  
Comment by Sander Qui 02 Fev 2012 16:57:19 UTC