The option without + is executed during parsing of the code. I assume this was done to allow you to write multiple lines in a row in your code so that you can:
test = "This is a line that is " \ "too long to fit nicely on the screen."
I assume that when possible, you should use the non-+ version, because there will only be a result string in the byte code, no signs of concatenation remain.
When you use + , you have two lines in the code, and you do concatenation at runtime (unless the interpreters are smart and optimize it, but I don't know if they do).
Obviously you cannot do: a = 'A' ba = 'B' a
Which one is faster? Version no-+ , as it is executed before the script is executed.
+ vs join โ If you have many elements, join is preferred because it is optimized to handle many elements. Using + to concat multiple lines creates many partial results in process memory, but using join does not.
If you are going to use only a couple of elements, I think + better, since it is more readable.
Maciek
source share