Python zfill() 方法


描述

Python zfill() 方法返回指定長度的字符串,原字符串右對齊,前面填充0。

語法

zfill()方法語法:

S.zfill(width)

參數

  • width -- 指定字符串的長度。原字符串右對齊,前面填充0。

返回值

返回指定長度的字符串。

實例

以下實例展示了 zfill() 方法的使用方法:

#!/usr/bin/python3

S = "this is string example from runoob....wow!!!"
print ("S.zfill : ",S.zfill(40))
print ("S.zfill : ",S.zfill(50))

以上實例輸出結果如下:

S.zfill :  this is string example from runoob....wow!!!
S.zfill :  000000this is string example from runoob....wow!!!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM