Since Python\'s string
can\'t be changed, I was wondering how to concatenate a string more efficiently?
I can write like it:
s += string
While somewhat dated, Code Like a Pythonista: Idiomatic Python recommends join()
over +
in this section. As does PythonSpeedPerformanceTips in its section on string concatenation, with the following disclaimer:
The accuracy of this section is disputed with respect to later versions of Python. In CPython 2.5, string concatenation is fairly fast, although this may not apply likewise to other Python implementations. See ConcatenationTestCode for a discussion.