相关疑难解决方法(0)

我似乎无法在 python 中找到前面的零的正确格式规范

添加小数位时,很简单

john = 2
johnmod = format(john, '.2f')
print(johnmod)
Run Code Online (Sandbox Code Playgroud)

正如预期的那样,我得到了 2.00 的回报。但是,添加前面的零的格式规范是什么?我希望输出为 0002,而我在 Google 上找到的唯一规范是使用 %04d,但它不起作用。如果重要的话,我在 Windows 上运行 Python 3.3。

python string int formatting

3
推荐指数
1
解决办法
532
查看次数

标签 统计

formatting ×1

int ×1

python ×1

string ×1