I need to output 4 different floats to two decimal places.
This is what I have:
print \'%.2f\' % var1,\'kg =\',\'%.2f\' % var2,\'lb =\',\'%.2f\' % va
Not directly in the way you want to write that, no. One of the design tenets of Python is "Explicit is better than implicit" (see import this
). This means that it's better to describe what you want rather than having the output format depend on some global formatting setting or something. You could of course format your code differently to make it look nicer:
print '%.2f' % var1, \
'kg =' ,'%.2f' % var2, \
'lb =' ,'%.2f' % var3, \
'gal =','%.2f' % var4, \
'l'