[Tutor] Field Width
Peter Otten
__peter__ at web.de
Thu Sep 19 11:24:20 CEST 2013
Jenny Allar wrote:
> I'm only a few days in to learning Python, so please bear with me.
Welcome!
> I need to line up the decimals on the printed information but I cannot get
> the text to look uniform at all.
> print("The cost of the carpet is $", format(subtotal,'9,.2f'))
> print("The flat fee is $", format(fee,'9,.2f'))
Just add some spaces manually:
print("The cost of the carpet is $", format(subtotal,'9,.2f'))
print("The flat fee is $", format(fee,'9,.2f'))
This is usually written as
print("The cost of the carpet is $ {:9,.2f}".format(subtotal))
print("The flat fee is $ {:9,.2f}".format(fee))
If this is not what you want you need to give more details; for instance:
the above won't look "uniform" when it is displayed in a proportional font.
More information about the Tutor
mailing list