[Python-ideas] Descouraging the implicit string concatenation

Rhodri James rhodri at kynesim.co.uk
Wed Mar 14 12:03:21 EDT 2018


On 14/03/18 12:18, Facundo Batista wrote:
> What would you think about formally descouraging the following idiom?
> 
>      long_string = (
>          "some part of the string "
>          "with more words, actually is the same "
>          "string that the compiler puts together")

-1.  I use it a fair bit, and prefer it to explicit concatenation.  But 
then I come from C, so I'm used to it.

 > Note that there's no penalty in adding the '+' between the strings,
 > those are resolved at compilation time.

Is that assertion true?  In all Python compilers?  I would expect the 
constant string implicit concatenation to produce single constants 
efficiently, but explicit concatenation doing the constant folding is a 
much less sure bet.

-- 
Rhodri James *-* Kynesim Ltd


More information about the Python-ideas mailing list