Multiline parsing of python compiler demistification needed

Lawrence D’Oliveiro lawrencedo99 at gmail.com
Thu Jun 23 00:55:51 EDT 2016


On Thursday, June 16, 2016 at 8:34:46 PM UTC+12, Yubin Ruan wrote:
> print "A test case" + \
>        "str_1[%s] " + \
>        "str_2[%s] " % (str_1, str_2)

Try this:

print \
  (
        "A test case"
        "str_1[%s] "
        "str_2[%s] "
    %
        (str_1, str_2)
  )

Python takes this nifty feature from C where multiple string literals in a row are implicitly concatenated into a single string.

If you come from a Java or C# background, you probably didn’t know about this, because those languages neglected to include this facility.



More information about the Python-list mailing list