[Tutor] Newline question

Alexander Q. redacted@example.com
Fri Aug 3 22:18:20 CEST 2012


I'm following the tutorial from python.org (
http://docs.python.org/tutorial/introduction.html) and am having a
few indiscrepancies regarding the new line command.

The tutorial says that this code

hello = "This is a rather long string containing\n\
several lines of text just as you would do in C.\n\
*        *Note that whitespace at the beginning of the line is\
 significant."

should yield this output:

This is a rather long string containing
several lines of text just as you would do in C.
    Note that whitespace at the beginning of the line is significant.

When I run it in the interpreter however, I get the following output:

'This is a rather long string containing\nseveral lines of text just
as you would do in C.\n    Note that whitespace at the beginning of
the line is significant.'


The interpreter is not reading the "\n" as new lines but is instead
printing them. If I just type something like

hello = "This is a rather long string containing \
several lines of text."


the output is all on one line, like this: "This is a rather long string
containing several lines of text." So I know how to combine code that spans
multiple lines to be outputted on one line, but I do not know how to make a
newline appear in the output upon command (on account of the interpreter
not reading the \n).

Any suggestions as to why my output varies from the output in the tutorial?
I am running a 2.7 version of Python, btw, and the tutorial is running a
higher version I believe (3. something). Thank you.

-Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120803/96ba0291/attachment.html>


More information about the Tutor mailing list
l>