Meaning of `\newline` as escape sequence

Discussion in 'Python' started by Marco, Dec 28, 2012.

  1. Marco

    Marco Guest

    Marco, Dec 28, 2012
    #1
    1. Advertising

  2. On Sat, Dec 29, 2012 at 2:42 AM, Marco <> wrote:
    > Hi all, in the documentation:
    >
    > http://docs.python.org/3.3/reference/lexical_analysis.html
    >
    > the escape sequence `\newline` is expained as "Backslash and newline
    > ignored". What does it mean?


    It means this:

    >>> foo = "This is\

    one string."
    >>> foo

    'This is one string.'

    Note that the leading space isn't an indent - it's just part of the
    quoted string. There's no newline in the resulting string, unlike what
    happens with a triple-quoted string. The backslash and line break are
    both ignored, meaning that the string is exactly the same as if they
    hadn't been there.

    But be careful with this sort of thing - a single trailing space on
    the line with the backslash will break the string syntactically. The
    backslash has to be the absolute last character on the line.

    ChrisA
     
    Chris Angelico, Dec 28, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. h babu
    Replies:
    1
    Views:
    410
    Vidar Petursson
    Jul 16, 2003
  2. marcia

    escape sequence \n

    marcia, Aug 28, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    553
    marcia
    Aug 28, 2003
  3. slomo
    Replies:
    5
    Views:
    1,546
    Duncan Booth
    Dec 2, 2007
  4. Replies:
    4
    Views:
    770
  5. Francois Grieu
    Replies:
    4
    Views:
    665
    Tim Rentsch
    Apr 29, 2011
Loading...

Share This Page