What's wrong with this concatenation statement?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon May 9 03:53:45 EDT 2016


On Monday 09 May 2016 09:10, DFS wrote:

> sSQL =  "line 1\n"
> sSQL += "line 2\n"
> sSQL += "line 3"

Pointlessly provocative subject line edited.

Since all three lines are constants know by the programmer at the time the 
source code is written, it should be written as:


sSQL = """line 1
line 2
line 3"""

Or if you prefer:

sSQL = "line 1\nline 2\nline 3"


Or even:

sSQL = ("line 1\n"
        "line 2\n"
        "line 3")

taking advantage of Python's compile-time implicit concatenation of string 
constants.



-- 
Steve




More information about the Python-list mailing list