Single string print statements on multiple lines.

H

HeEm

In my 100 level CS course, I was asked to create multiple lines of
output within a single string. Of course I know how to:

print "I am"
print "a python"
print "newbie."

How can I get this accomplished using a single string (assuming this
means a one line statement). Is there and escape character or
something that could be added?

Thanks for any help that can be provided.
 
D

Diez B. Roggisch

HeEm said:
In my 100 level CS course, I was asked to create multiple lines of
output within a single string. Of course I know how to:

print "I am"
print "a python"
print "newbie."

How can I get this accomplished using a single string (assuming this
means a one line statement). Is there and escape character or
something that could be added?

Thanks for any help that can be provided.

The usual one: \

Do

"first line\nnextline"

Diez
 
M

MonkeeSage

HeEm said:
In my 100 level CS course, I was asked to create multiple lines of
output within a single string. Of course I know how to:

If this is for a CS course, you shouldn't really be cheating and
asking for an answer here, should you? I mean, the whole point of
taking (and paying for!) a CS course is to learn CS, right? But like
Diez said, the standard C escapes work in python: \t = TAB, \r =
CARRIAGERETURN, \n = NEWLINE/LINEFEED, &c.

Regards,
Jordan
 
S

Steven D'Aprano

If this is for a CS course, you shouldn't really be cheating and
asking for an answer here, should you? I mean, the whole point of
taking (and paying for!) a CS course is to learn CS, right?

"Always go over old ground, re-inventing the wheel again and again" is the
least efficient, most error-prone way of learning comp sci (or any other
subject for that matter).

There's a fuzzy line between "help me to learn this" and "do my work for
me", but it is a real distinction. One of the distinguishing
characteristics of an educated person and an ignoramus is that the
educated person not only knows more stuff, but more importantly knows how
to find out what he doesn't already know. That can include looking it up
in a reference book or asking somebody who does know.
 
B

Bruno Desthuilliers

Goldfish a écrit :
Given the way the question was expressed, I don't think this particular
rule applies here. Obviously, the OP is not trying to cheat (explicitelt
aknowledging it is homework), and has a good enough understanding of
what the usual solution is (asking for the escape char in Python).

Now of course the answer is in the FineManual(tm), which implies that
either the OP failed to read it, or that the FineManual is not so fine -
but that's another problem.

My 2 cents...
 
G

Gabriel Genellina

En Tue, 13 Mar 2007 08:31:17 -0300, Bruno Desthuilliers
Obviously, the OP is not trying to cheat (explicitelt
aknowledging it is homework), and has a good enough understanding of
what the usual solution is (asking for the escape char in Python).

Now of course the answer is in the FineManual(tm), which implies that
either the OP failed to read it, or that the FineManual is not so fine -
but that's another problem.

If the FineManual(tm) is the Tutorial, it only explain escape sequences
minimally, presuming some prior knowledge on the reader. For users with
previous experience in different languages (like VB or Delphi) using \n is
rather strange.
 
D

Dennis Lee Bieber

If the FineManual(tm) is the Tutorial, it only explain escape sequences
minimally, presuming some prior knowledge on the reader. For users with

No, the tutorial is aimed at /introducing/ the concept of escape
sequence <G>

There are also the Language Reference Manual, and the Library
Reference Manual.

These are where the detailed information will be found.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top