Python zfill()メソッド
説明
Python zfill() メソッドは、指定された長さの文字列を返します。元の文字列は右寄せで、前に0が埋められます。
構文
zfill()メソッドの構文:
str.zfill(width)
パラメータ
- width -- 文字列の長さを指定します。元の文字列は右寄せで、前に0が埋められます。
戻り値
指定された長さの文字列を返します。
インスタンス
以下のインスタンスは、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!!!
その他の拡張
Python 文字列