正数补前面补0
n = ""
s = n.zfill(5)
assert s == "" zfill()也可以给负数补0
n = "-123"
s = n.zfill(5)
assert s == "-0123" 对于纯数字,我们也可以通过格式化的方式来补0
n = 123
s = "%05d" % n
assert s == ""
2023-12-06 08:41:40
正数补前面补0
n = ""
s = n.zfill(5)
assert s == "" zfill()也可以给负数补0
n = "-123"
s = n.zfill(5)
assert s == "-0123" 对于纯数字,我们也可以通过格式化的方式来补0
n = 123
s = "%05d" % n
assert s == ""