620 shaares
Be wary, apparently, using the "shorthand" operators in Python is NOT an equivalent of the "longhand" operator.
foo += bar (and all its similar counterpart) does NOT do the same as foo = foo + bar.
The first one is able to update the variable in place, whereas the second one will create a copy.
It's a bit more intricate than that so make sure to check the link for detailed explanation.
I saw this on LinkedIn and I actually didn't know this unfortunately… (not that I wrote any Python recently)
Maybe this is common knowledge: I apologize if so!
It's a shame that this goes a bit against one of the Zen of Python's motto: Explicit is better than implicit.