Printing strings

François Pinard pinard at iro.umontreal.ca
Tue Nov 2 15:27:46 CET 1999


Matthew Hirsch <meh9 at cornell.edu> writes:

>    a=4.0
>    b=2.0
>    print '2(%3.1f)' % a,b
> where I really mean
>    print '%3.1f %3.1f' % a,b
> but it's printing
>    2(4.0) 2.0
> Is there a way of doing this so I don't have to write out %3.1f,
> multiple times?

Maybe you could play around this idea?

>>> a, b = 4.0, 2.0
>>> print '%4.1f' * 2 % (a, b)
 4.0 2.0

I changed `%3.1f' into `%4.1f' because `4.02.0' would not look nice.)

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list