4

How can I set 40 to be a variable let say temp which calculate on the fly and passed instead of 40 in this format string:

{:<40}.format('aa')

0

1 Answer 1

6

Something like this should work:

>>> width = 40
>>> '{0:<{width}}'.format('aa', width=width)
'aa                                      '
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.