3

I have this piece of code and I'm trying to figure out how to have multiple arguments in that second set of brackets. I want the number to be right aligned in 6 places and rounded to 2 decimal points. I get the error 'invalid format specifier' every time.

print("{0:>5}   {1:>6, 6.2f}".format(pounds, euros))
1

1 Answer 1

1

If you read the Format Specification Mini-Language, you'll notice that one can only specify the format width once and precision appears after the '.':

>>> "{0:>5}   {1:>6,.2f}".format(10, 1500.657)
'   10   1,500.66'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.