One of the less intuitive assignments to variables is augmented assignment to a list. The code here replaces a list variable by concatenation in several ways.


Augmented Assignent to List

M = "one two three".split()
M += ["four"]
M = "one two three".split()
M += [True] + M
M = "one two three".split()
M += "four"


Most beginners do not see what is most probably a bug in the last line of the example. Realize that for a list M, an expression M + 7 is an error because concatenation only works if both terms are sequences (7 is not a sequence). Technically, M + "four" works because "four" is a sequence (a string). That explains how Python handles the last augmented assignment of the example.