Note: The code links are to CPython 3.8.5, the most recent release when this was written.
I was recently asked about a performance optimization in CPython around using +=
and +
for string objects.
As some people may already know, if you use +=
or +
a string, it can sometimes be just as fast as ''.join
.
The question was to explain when that optimization couldn't be performed.
We will be going through the following example scenarios: