n00b question on spacing
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri Jun 21 21:27:55 EDT 2013
On Fri, 21 Jun 2013 17:48:54 -0400, Ray Cote wrote:
> Also remember when entering long lines of text that strings concatenate
> within parenthesis. So,
> ("a, b, c"
> "d, e, f"
> "g, h, i")
>
> Is the same as ("a, b, cd, e, fg, h, i")
Technically, you don't need the parentheses. You can also use backslash
to continue the lines:
s = "a, b, c, " \
"d, e, f, " \
"g, h, i"
assert s == "a, b, c, d, e, f, g, h, i"
Or, if the strings are small enough, fit them on one line:
s = "a" "b" "c"
This *implicit concatenation* only works with string literals, not
variables, but it works with any sort of quoting style:
s = "-'-" '-"-' r"\a\b"
assert s == "-'--\"-\\a\\b"
Like most such features, a little goes a long way. Don't over do it, it
is quite possible to end up with an unreadable mess if you overuse it.
--
Steven
More information about the Python-list
mailing list