代码点读机 / Python / zfill

zfill Python · 字符串方法

在字符串左边补零,直到达到指定宽度。

怎么用

字符串.zfill(宽度)

小例子

print('42'.zfill(5))

运行结果

00042

官方文档:https://docs.python.org/zh-cn/3/library/stdtypes.html#string-methods

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条