3 ms·
More of a "Meh" moment for me. > Python strings are immutable ... So adding them involves creating new strings all the time, which is inefficient ... Instead,
by chrisjj 2y ago
More of a "Meh" moment for me.
> Python strings are immutable ... So adding them involves creating new strings all the time, which is inefficient ... Instead, you can append the strings to a list. Lists are mutable, so it’s faster. Then you simply join them all at the end using the str.join() method.
Don't we have computers to do such work? Give a man a fish, etc. but give him a smart compiler...
- Doxin 2y agoIIRC this is already optimized these days. Go concat strings naively to your hearts content.