Python 3 教程
Python zfill() 方法返回指定長度的字符串,原字符串右對齊,前面填充0。
zfill()方法語法:
str.zfill(width)
返回指定長度的字符串。
以下實例展示了 zfill()函數(shù)的使用方法:
#!/usr/bin/python3 str = "this is string example from json....wow!!!" print ("str.zfill : ",str.zfill(40)) print ("str.zfill : ",str.zfill(50))
以上實例輸出結果如下:
str.zfill : this is string example from json....wow!!! str.zfill : 000000this is string example from json....wow!!!