Separator in print statement

Matt Goodall matt at pollenation.net
Tue Oct 14 12:29:13 EDT 2003


Bertram Scharpf wrote:

>Hi,
>
>when I write
>
>    >>> print 'abc', 'def',
>    >>> print 'ghi'
>
>I get the output 'abc def ghi\n'.
>
>Is there a way to manipulate the print
>statment that I get for example:
>
>'abc, def, ghi\n'
>
>I mean: can I substitute the ' ' separator produced from
>the comma operator by a e.g. ', ' or something else?
>

print '%s, %s, %s' % ('abc', 'def', 'ghi')

or better still

print ', '.join(('abc', 'def', 'ghi'))

If you want super-fine control then don't use print, use sys.stdout.write().

Cheers, Matt

-- 
Matt Goodall, Pollenation Internet Ltd
w: http://www.pollenationinternet.com
e: matt at pollenation.net







More information about the Python-list mailing list