[docs] Bug in tutorial

Zachary Ware zachary.ware+pydocs at gmail.com
Wed Mar 26 15:41:06 CET 2014


Hi,

On Wed, Mar 26, 2014 at 12:11 AM, 1 2 <bothenta at gmail.com> wrote:
> There is a bug on chapter 3.1.2 on strings
>
> "End of lines are automatically included in the string, but it’s possible to
> prevent this by adding a \at the end of the line. The following example:"
>
> It said to add "\" at the end of the line.
>
> But in the example, it added backslash at the begin of the line

The example looks correct to me.  Note that the backslash is at the
beginning of the string, not the beginning of a line.  Here is a
sample session that will hopefully make things a little clearer for
you:

   >>> """first line
   ... second line
   ... third line
   ... fourth line"""
   'first line\nsecond line\nthird line\nfourth line'
   >>> print(_)     # At the interactive prompt, _ is always the last result
   first line
   second line
   third line
   fourth line
   >>> """\
   ... first line
   ... second line
   ... third line (empty fourth line follows)
   ... """
   'first line\nsecond line\nthird line (empty fourth line follows)\n'
   >>> print(_)
   first line
   second line
   third line (empty fourth line follows)

   >>> """\
   ... first line
   ... second line\
   ...  still second line
   ... third line with no trailing newline\
   ... """
   'first line\nsecond line still second line\nthird line with no
trailing newline'
   >>> print(_)
   first line
   second line still second line
   third line with no trailing newline

Basically, a '\' at the end of a physical line causes the logical line
to continue.  Does that make sense?

The example above is way too long to add to the documentation, but if
you can suggest any way to tweak the docs to make things clearer,
please let us know!

Regards,

-- 
Zach


More information about the docs mailing list