python - 我想打印与列表中指定的相同的整数值

标签 python python-2.7

the_count = [001, 002, 003, 004, 005]
for number in the_count:
    print(number)

输出是:

1
2
3
4
5

我的预期输出是:

001
002
003
004
005

最佳答案

print('{0:03d}'.format(number))

或者看看 zfill 或 rjust

关于python - 我想打印与列表中指定的相同的整数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36690398/

相关文章:

python - lambda 如何与 reduce 一起工作

Python:创建网格

python - “NoneType”对象在 Chartit 中不可迭代

python - Pytest中如何控制增量测试用例

python - 使用 boto 和 python 从带有参数的布局创建 mTurk HIT

python - 从文件保存和加载类实例

python - 我们需要挑选任何类型的可调用对象

python - 删除文本文件中每一行的最后一个字符

python - 绘制两点之间的圆弧路径

django - 在 Python 2.7 中使用 unicode_literals 时在 Django 中解码 utf-8