无涯教程-Python - zfill (width)函数

206 阅读1分钟

Python zill()用零填充左侧的字符串以填充宽度。

zfill (width) - 语法

str.zfill(width)
  • width  -  这是字符串的最终宽度。这是填充零后得到的宽度。

zfill (width) - 返回值

此方法返回填充字符串。

zfill (width) - 示例

以下示例显示了zill()方法的用法。

#!/usr/bin/python

str="this is string example....wow!!!"; print str.zfill(40) print str.zfill(50)

当无涯教程运行上面的程序时,它产生以下输出-

00000000this is string example....wow!!!
000000000000000000this is string example....wow!!!

参考链接

www.learnfk.com/python/stri…