目录

zfill (width)

描述 (Description)

zfill()方法在左边填充字符串,用零填充宽度。

语法 (Syntax)

以下是zfill()方法的语法 -

str.zfill(width)

参数 (Parameters)

  • width - 这是字符串的最终宽度。 这是填充零后我们得到的宽度。

返回值 (Return Value)

此方法返回填充字符串。

例子 (Example)

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

#!/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!!!
↑回到顶部↑
WIKI教程 @2018