[Tutor] mistaken about splitting expressions over lines

eryksun eryksun at gmail.com
Tue Jun 25 14:14:51 CEST 2013


On Mon, Jun 24, 2013 at 9:58 PM, Dave Angel <davea at davea.name> wrote:
>
> Alternatively, you can also use the statement continuation mechanism,
> whereby the last character of the line is a backslash.  Using that approach
> you can break almost anywhere, except within a token or inside a string
> literal.

Also, the next character after a line continuation has to be a
newline, e.g. no spaces, tabs, or comments. Your editor should have a
feature to remove trailing white space on each line.

    >>> a = 'this' \
      File "<stdin>", line 1
        a = 'this' \
                    ^
    SyntaxError: unexpected character after line continuation character


    >>> a = ('this'  # this way
    ...      ' string' ' is long') # is more flexible
    >>> a
    'this string is long'


More information about the Tutor mailing list