zfill()方法用零墊串來填充左邊寬度。
語法
以下是zfill()方法的語法:
1
|
str .zfill(width) |
參數
- width -- 這是字符串的最終寬度,即填充零后得到的寬度。
返回值
此方法返回補齊的字符串。
例子
下面的例子顯示了zfill()方法的使用。
1
2
3
4
5
6
|
#!/usr/bin/python str = "this is string example....wow!!!" ; print str .zfill( 40 ); print str .zfill( 50 ); |
當我們運行上面的程序,它會產生以下結果:
1
2
|
00000000this is string example....wow!!! 000000000000000000this is string example....wow!!! |