How do I format the width of a string with a computed runtime variable?

How can I set 40

as a let say variable temp

which are computed on the fly and passed instead 40

in this format string:

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

+3


source to share


1 answer


Something like this should work:



>>> width = 40
>>> '{0:<{width}}'.format('aa', width=width)
'aa                                      '

      

+5


source







All Articles