A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-November/050125.html below:

[Python-Dev] String literal concatenation & docstrings

[Python-Dev] String literal concatenation & docstrings [Python-Dev] String literal concatenation & docstringsGuido van Rossum gvanrossum at gmail.com
Sat Nov 27 18:13:25 CET 2004
> It means that:
> 
>     print "this line continues"
>           "on the next line"
> 
> does not work, while the following works:
> 
>     a = "this line continues"
>         "on the next line"

As has been pointed out already, it doesn't.

The right way to look at this is not using the statement/expression
distinction, but to look at whether the newline between the two
literals is significant to the parser or not. A significant newline
ends a statement; an insignificant one is equivalent to a space. The
rule is that newlines (outside string quotes anyway) are significant
unless either escaped with \, or contained within matching
parentheses.

So if you want to print or assign a long string broken across multiple
lines without having to use triple-quoted strings (which have their
own set of issues), you can write this:

    print ("this line continues"
           " on the next line")

Note that I fixed a common buglet in your example: the words
"continues" and "on" should be separated by a space. Not important for
the example, of course, but (having used this idiom and similar ones a
lot) something to keep in mind when splitting a long string across a
line this way.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4