Simple thing about printing

Alex Martelli aleax at
Thu Mar 13 09:48:01 CET 2003

Luke McCarthy wrote:

> It's funny how you use Python for a while and then something very simple
> comes up and stops you.
> How can I print without a newline being automatically inserted at the end?

If you end the statement with a comma you insert a space rather
than a newline, e.g.:

    print 'hello',
    print 'there'

emits the line

hello there

If you don't want the extra space either, don't use print, but rather
import sys and use sys.stdout.write, i.e.:

import sys

emits the line



More information about the Python-list mailing list