print ending with comma

André Roberge andre.roberge at
Tue Jul 19 17:58:49 CEST 2005

jamesthiele.usenet at wrote:
> A "\n" character is written at the end, unless the print statement ends
> with a comma.
> What it doesn't say is that if the print statement does end with a
> comma, a trailing space is printed.
> --
> But this isn't exactly correct either. If you run this program:
> import sys
> print '+',
> print '-',
> sys.stdout.write('=')
> print
> --
> the output is:
> + -=
> I know that this is not a massively important issue, but can someone
> explain what's going on?
Actually, it is not a trailing space but a leading space
that is stored and displayed when print is called next.
 >>> import sys
 >>> print 'a',
 >>> print 'b',
sys.stdout.write() does not include such a leading space.

Time to consult about the print statement.:

...A space is written before each object is (converted and) written, 
unless the output system believes it is positioned at the beginning of a 

Yep, another case of RTM :-)


More information about the Python-list mailing list