About printing in IDLE?

D

Dr. Pastor

Installed Python 2.4.2 on Windows XP.
Activated IDLE.
Loaded the following to the Edit window:
---
print "hello world"
for i in range(10):
print i,

print "Done"
 
D

Dustan

Dr. Pastor said:
Installed Python 2.4.2 on Windows XP.
Activated IDLE.
Loaded the following to the Edit window:
---
print "hello world"
for i in range(10):
print i,

print "Done"

the comma after print i means the next print statement will print on
the same line. It prints 9, an then the next print statement is "Done".
It prints on the same line. If you want it on a newline, try:

print "\nDone"
 
T

Terry Reedy

Dr. Pastor said:
Installed Python 2.4.2 on Windows XP.
Activated IDLE.
Loaded the following to the Edit window:
---
print "hello world"
for i in range(10):
print i,

print "Done"

I would put a bare print statement immediately after the loop to finish the
loop output, and maybe add a comment to that effect.

print # finish line generated by loop above

I would not leave the line hanging until something else is printed, nor
fiddle with making last line of loop different.

Terry Jan Reedy
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top