Q: What is the difference between list += str and list += str, Today I noticed a strange behavior while doing some python list operations. 
Lets say, 
a = []
b = 'xy'

When I do, a += b the interpreter returns: 
a += b
a == ['x', 'y']

but when I do, a += b, (with a comma) the interpreter returns a = ['xy']
a += b,
a == ['xy']

Can someone please explain what is happening here.

A: a += b

When a is a list, this operation is similar to a.extend(b).  So it iterates the object b, appending each element to a.
If you iterate the string 'xy', it yields two elements 'x' and 'y'.
If you iterate the tuple 'xy',, it yields one element 'xy'.

A: The line
a += b,

is equivalent to
a += (b, )

It creates a tuple with one item. If it is added, the item 'xy' it added to a.
If you add a string like 'xy' it counts as a sequence of characters on it's own and every sequence item (character) is added individually to a.
So basically the comma wraps b into a tuple.

A: Comma creates tuple - so a += b, means the same as a += (b,)
a += ('xy', )

You add tuple with one element so it almost like 
a += ['xy']

so you have
a = [] + ['xy']

which gives result
a = ['xy']

