如何使用 format 属性在 python 3.2 中获取整数以将 0 填充为固定宽度?例子:
a = 1
print('{0:3}'.format(a))
给出我想要的 '1' 而不是 '001'。在 python 2.x 中,我知道这可以使用
print "%03d" % number.
我检查了 python 3 字符串文档,但无法得到这个。
http://docs.python.org/release/3.2/library/string.html#format-specification-mini-language
谢谢。