[Tutor] 'print' without newline or space appended

Marcin Komorowski marcink at ieee.org
Sun Sep 25 16:20:46 CEST 2005


Hello,

This statement:
  for c in 'hello': print c
will generate following output:
  h
  e
  l
  l
  o
and by adding comma at the end of the print statement:
  for c in 'hello': print c,
we get this output:
  h e l l o
How do I output something using 'print' such that there is no new line or 
space appended at the end of the output.

....

Hehe... just answered my own question:
  import sys
  for c in 'hello' : sys.stdout.write(c)
Is this the way to do it or is there a more appropriate approach.

Thanks,
Marcin 




More information about the Tutor mailing list