【发布时间】:2022-07-25 20:24:53
【问题描述】:
以下问题: How to set the spaces in a string format in Python 3
为什么第一个有效,第二个无效?
string='Hello World!'
length = 20
print('{1:>{0}}'.format(length, string))
结果: Hello World!
string='Hello World!'
length = len(string)
print('{1:>{0}}'.format(length, string))
结果:Hello World!
【问题讨论】:
标签: python string integer format output