473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Single string print statements on multiple lines.

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.

Mar 12 '07 #1
6 2269
HeEm wrote:
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
Mar 12 '07 #2
HeEm wrote:
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

Mar 12 '07 #3
http://www.catb.org/~esr/faqs/smart-questions.html

Don't post homework questions.

Mar 12 '07 #4
On Mon, 12 Mar 2007 05:40:44 -0700, MonkeeSage wrote:
HeEm wrote:
>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?
"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.

--
Steven D'Aprano

Mar 13 '07 #5
Goldfish a écrit :
http://www.catb.org/~esr/faqs/smart-questions.html

Don't post homework questions.
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...


Mar 13 '07 #6
En Tue, 13 Mar 2007 08:31:17 -0300, Bruno Desthuilliers
<br********************@wtf.websiteburo.oops.comes cribió:
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.

--
Gabriel Genellina

Mar 13 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jon Smith | last post by:
Is there anyway to make new lines in single quotes? Thanks, Jon Smith
4
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from...
3
by: Colleyville Alan | last post by:
I am constructing a SQL command from a function. Some code builds the WHERE clause in a looping structure and passes that as an argument to the SQL-building function. But the results do not...
5
by: Bauer | last post by:
I am new to GDI+.I am drawing a string on the Win form using GDI+. My string content is long and it does not have any "vbcrlf". The whole string is displayed in a single line and is getting...
2
by: L. Berger | last post by:
Hi, I am working on an HTML template which has a lot of html tags, with PHP data shown in the middle of these tags -- you know, the usual. Currently, I have HTML as is, and many many "echo...
2
by: =?Utf-8?B?VGVycnk=?= | last post by:
I have coded multiple select statements in a single stored procedure, and when I execute this procedure on SQL Server Management Express, I correctly get multiple result sets. But, if I try to add...
9
by: vedrandekovic | last post by:
Hello, I have one question about string.I am trying to make an function to analyze line of some text, this is my example: "HELLO;HELLO2:WORLD:", if that function in this text find ";" and ":" (...
19
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
This is an example of the data; 2007/07/27 11:00:03 ARES_INDICATION 010.050.016.002 404.2.01 (6511) RX 74 bytes 2007/07/27 11:00:03 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13 48...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.