Python Forum
formatting question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: formatting question (/thread-14163.html)



formatting question - Jonininireland - Nov-17-2018

using format

such as

pizzaTotal = 5
formatPizzaTotal = '{:>75}'.format(pizzaTotal)

i know moves the print 75 spaces to the right

but if i have

myString = "I have"
pizzaTotal = 10
totalPrice = pizzaTotal * 10.00

how can i print
I have [spaces] 10 pizzas [spaces] €total:100.00

also can all of this be done with one format line, or does each one have to be done seperate
also how can i get the $ in my format if i print it first it goes $ 5 ie it doesnt move with the format

and how can i get all decimals lined up from the right ie zeroes on the right
-----10.00
----100.00
---1000.00

i know i can just space them but if the values change they will be out of line

thanks


RE: formatting question - Gribouillis - Nov-17-2018

This perhaps ?
>>> "{:<10}{: >20}{: >25}".format('I have', '10 pizzas', '€ {:.2f}'.format(100))
'I have               10 pizzas                 € 100.00'
>>> "{:<10}{: >20}{: >25}".format('I have', '5 pizzas', '€ {:.2f}'.format(50))
'I have                5 pizzas                  € 50.00'