I'm having a tough time finding the exact wording for my question since I'm new to formatting strings.
Let's say I have two variables:
customer = 'John Doe'
balance = 39.99
I want to print a line that 25 characters wide, and fills the space between the two values with a specific character (in this case, periods):
'John Doe .......... 39.99'
So as I loop through customers, I want to print a line that is always 25 characters, with their name at the left, and their balance at the right, and allow the periods to adjust to fill the space between.
I can break this into multiple steps and accomplish the result...
customer = 'Barry Allen'
balance = 99
spaces = 23 - len(customer + str(balance))
'{} {} {}'.format(customer, '.' * spaces, balance)
# of course, this assumes that len(customer + str(balance)) is less than 23 (which is easy to work around)
...but I'm curious if there is a more "elegant" way of doing it, such as with string formatting.
Is this even possible?
Thanks!