python - How to format string width with a runtime calculated variable? -
how can set 40 variable allow temp calculate on fly , passed instead of 40 in format string:
{:<40}.format('aa')
something should work:
>>> width = 40 >>> '{0:<{width}}'.format('aa', width=width) 'aa ' python python-2.7
No comments:
Post a Comment