当前位置:首页 - 建站教程 - python教程 - python自动给数字前面补0的方法

python自动给数字前面补0的方法

时间:2018-12-15来源: 作者: 文章热度:
点评:-python中有一个zfill方法用来给字符串前面补0,非常有用 n = "123" s = n.zfill(5) as
-python<...中有一个zfill方法用来给字符串前面补0,非常有用
= "123"
= n.zfill(5)
assert == "0.123"
zfill()也可以给负数补0
= "-1.3"
= n.zfill(5)
assert == "-0123"
对于纯数字,我们也可以通过格式化的方式来补0
= 123
= "%05d" % n
assert == "00123"
帝国cms总结,在处理时间的时候需要补零很有用。
文章TAG:python 补零
相关python教程
最新python教程