今天爱分享给大家带来python如何填充0到数字字符串中保证统一长度【面试题详解】,希望能够帮助到大家。
对于字符串
>>> n = '4' >>> print n.zfill(3) >>> '004'
对于数字
>>> n = 4
>>> print '%03d' % n
>>> 004
>>> print "{0:03d}".format(4) # python >= 2.6
>>> 004
>>> print("{0:03d}".format(4)) # python 3
>>> 004
原文链接:https://blog.itblood.com/3921.html,转载请注明出处。

![街头斗士:成人游乐场战斗Battle8.4 AI版[PC+安卓/1.54G/更新]Street Brawlers: Adult Playground [Battle 8.4] [欧美SLG/汉化/动态]](/wp-content/uploads/replace/2025/09/16/2af8017bd4538116e1159699c7d86656.webp)