(no subject)

Charles G Waldman cgw at fnal.gov
Tue Nov 2 10:50:02 EST 1999


Matthew Hirsch writes:
 > Hi All,
 > 
 > I'm trying to do something like the following:
 > 
 > 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?
 > 

Try this construction:

print 2*"%3.1f " % (a,b)


Note that "%" binds more tightly than "," so if you want to print
multiple vars in one format string, you must say (for example)
 
print "%s %s %s" % (a,b,c)

rather than:

print "%s %s %s" % a, b, c







More information about the Python-list mailing list