Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
formatting question
#1
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
Reply
#2
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'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Question on HTML formatting with set string in message Cknutson575 3 3,410 Mar-09-2021, 08:11 AM
Last Post: Cknutson575
  Text formatting question ToddRyler 2 2,626 Dec-18-2017, 01:13 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020