Python 基礎(chǔ)教程
Python zfill() 方法返回指定長(zhǎng)度的字符串,原字符串右對(duì)齊,前面填充0。
zfill()方法語法:
str.zfill(width)
返回指定長(zhǎng)度的字符串。
以下實(shí)例展示了 zfill()函數(shù)的使用方法:
#!/usr/bin/python str = "this is string example....wow!!!"; print str.zfill(40); print str.zfill(50);
以上實(shí)例輸出結(jié)果如下:
00000000this is string example....wow!!! 000000000000000000this is string example....wow!!!