[Tutor] 'print' without newline or space appended
R. Alan Monroe
amonroe at columbus.rr.com
Sun Sep 25 16:29:05 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.
Also
outstring = ''
for c in 'hello':
outstring += c
print outstring
More information about the Tutor
mailing list