[Tutor] 'print' without newline or space appended
Marcin Komorowski
marcink at ieee.org
Sun Sep 25 19:59:04 CEST 2005
Thanks,
This is the other 'work around'. I take there is no way to tell 'print' to
do it, correct?
Marcin
----- Original Message -----
From: "R. Alan Monroe" <amonroe at columbus.rr.com>
To: "python-tutor" <tutor at python.org>
Sent: Sunday, September 25, 2005 10:29 AM
Subject: Re: [Tutor] 'print' without newline or space appended
>> 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
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list