Multi-Line Strings: A Modest Proposal
Steven D'Aprano
steve+python at pearwood.info
Sat Aug 13 23:34:07 EDT 2016
On Sun, 14 Aug 2016 11:53 am, John Wong wrote:
> The way I solve it, and I still find that extremely ugly, is
>
> s = ("this string continues " +
> "substring continues")
You don't need the plus sign, as Python will concatenate string literals
(not variables) at compile time:
"foo" 'bar' # compiles as 'foobar'
Note that you can mix any of the string delimiters, including raw strings.
And they don't have to be on the same line:
raise ValueError(
"This is a long 'error message' using"
' mixed "quotes" specifically so I can'
" show off Python's string literal concatenation."
)
That's equivalent to the one-line:
raise ValueError("This is a long 'error message' using mixed \"quotes\" specifically so I can show off Python's string literal concatenation.")
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse.
More information about the Python-list
mailing list