I find that string concatenation seems to have less python bytecode than list join.
This is an example.
test.py:
a = ''.join(['a', 'b', 'c'])
b = 'a' + 'b' + 'c'
Then I execute python -m dis test.py.
I got the following python bytecode (python 2.7):
1 0 LOAD_CONST 0 ('')
3 LOAD_ATTR 0 (join)
6 LOAD_CONST 1 ('a')
9 LOAD_CONST 2 ('b')
12 LOAD_CONST 3 ('c')
15 BUILD_LIST 3
18 CALL_FUNCTION 1
21 STORE_NAME 1 (a)
3 24 LOAD_CONST 6 ('abc')
27 STORE_NAME 2 (b)
30 LOAD_CONST 4 (None)
33 RETURN_VALUE
Obviously, the bytecode number of string concatenation is less.It just load string 'abc' directly.
Can anyone explain why we always say that list join is much better?

+, or usingsum()on many strings you don't know beforehand eventually results in a quadratic runtime, as opposed to.joinwhich is optimized.b='a' + 'b' + 'c'is taking advantage of constant folding, since all three operands are known at compile time. Try something likeb = a1 + a2 + a3, and you'll see more complex byte code generated.