今天爱分享给大家带来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,转载请注明出处。

![NTR由我的朋友v0.13.1 AI版[PC+安卓/3.99G/更新]NTR’ed by My Friend [v0.13.1] [亚洲SLG/汉化/动态]](/wp-content/uploads/replace/2025/10/17/3e5687f1e1bc0a99e1754adf77037910.webp)