>>> x = ['a', 'b']
>>> x
['a', 'b']
>>> x += 'c'
>>> x
['a', 'b', 'c']
>>> x += ''
>>> x
['a', 'b', 'c']
>>> x += ['']
>>> x
['a', 'b', 'c', '']
>>> 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:
and maybe
you might want to add:
and maybe
you might want to add:
and maybe
you might want to add:
and maybe
you might want to add:
and maybe
you might want to add:
and maybe
It seems that for a list x, the statement:
is internally translated into:Whereas for a list x, the statement
requires y to be a list.Python can iterate over a string, it's individual characters.
The same difference we see with sets:
Also, since a string is not iterable, this does not work: