Between a rock and a crazy place

Python-fnord of the day

06 May 2014

This is an argument of believe, but I think this is highly irregular and unexpected behaviour of python:

a = [1, 2, 3, 4]
b = a
a = a + [5]
print(b)
a = [1, 2, 3, 4]
b = a
a += [5]
print(b)

Output:

[1, 2, 3, 4]
[1, 2, 3, 4, 5]

Call me crazy, but in my world, x += y should behave exactly the same as x = x + y and this is another example, why operator overloading can be abused in absolutely horrible ways.

Never mind, that there is actually python teaching material out there that teaches wrong things. That is, there are actually people out there who think they know python well enough to teach it, but don't know this. Though credit where credit is due, the official documentation mentions this behaviour.