such as
In [9]: dis.disassemble(compile("s = '123' + '456'", "<execfile>", "exec"))
1 0 LOAD_CONST 3 ('123456')
3 STORE_NAME 0 (s)
6 LOAD_CONST 2 (None)
9 RETURN_VALUE
I want to know, when does python combine the constant string as the CONST.
If possible, please tell me which source code about this at cpython(whatever 2.x, 3.x).
It happens whenever the combined string is 20 characters or fewer.
The optimization occurs in the peephole optimizer. See line 219 in the
fold_binops_on_constants()function in Python/peephole.c: http://hg.python.org/cpython/file/cd87afe18ff8/Python/peephole.c#l149