newbie ``print`` question

gwhite gwhite at ti.com
Sun Sep 2 16:11:24 EDT 2012


On Sep 2, 11:33 am, Terry Reedy <tjre... at udel.edu> wrote:
> On 9/2/2012 1:23 PM, gwhite wrote:
>
> > I can't figure out how to stop the "add a space at the beginning"
> > behavior of the print function.
>
> >>>> print 1,;print 2,
> > 1 2
>
> You have discovered why print is a function in 3.x.
>  >>> print(1, 2, sep='')
> 12
>  >>> print(1, end=''); print(2, end='')
> 12
>
> In 2.6 or 2.7, you can add
>    from __future__ import print_function
> but I recommend using 3.2 or 3.3 unless you have a reason to use older
> Python.

It looks like one can avoid pre-construction of the total line with
3.x.

>>> from __future__ import print_function
>>> print('a=%.1f,' % 1.0, end='');print('b=%.1f' % 2.0, end='')
a=1.0,b=2.0

Thanks.  It isn't that hard to pre-construct, but regardless, there is
better control in 3.x.



More information about the Python-list mailing list