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. Advertisements

  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. Advertisements

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:
    554
    Vidar Petursson
    Jul 16, 2003
  2. marcia

    escape sequence \n

    marcia, Aug 28, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    679
    marcia
    Aug 28, 2003
  3. Jeff

    Unrecognized escape sequence

    Jeff, Jun 30, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    39,987
    mansoorbhai
    Jun 21, 2011
  4. N U

    escape sequence

    N U, Sep 12, 2003, in forum: C Programming
    Replies:
    7
    Views:
    719
    LibraryUser
    Sep 13, 2003
  5. Walter L. Preuninger II

    literal escape sequence conversion to raw

    Walter L. Preuninger II, Jan 5, 2004, in forum: C Programming
    Replies:
    6
    Views:
    661
    Kevin Goodsell
    Jan 5, 2004
  6. slomo
    Replies:
    5
    Views:
    2,133
    Duncan Booth
    Dec 2, 2007
  7. Replies:
    4
    Views:
    1,011
  8. Francois Grieu
    Replies:
    4
    Views:
    774
    Tim Rentsch
    Apr 29, 2011
Loading...