Adding a string to a list using augmented assignment

Strings are iterable: the elements are the string’s characters. When you add an iterable to a list, the iterable’s elements get appended to the list.

Either of the following will do what you’re expecting (i.e. append the string, not extend the list with the string’s characters):

b += [c]

or

b.append(c)

Leave a Comment