python3のzfill()メソッド
説明
Pythonのzfill()メソッドは、元の文字列右寄せ、ゼロ詰めフロントの長さを指定する文字列を返します。
文法
zfill()メソッドの構文:
str.zfill(width)
パラメータ
- 幅 - 文字列の長さを指定します。 元の文字列は右、ゼロ詰めフロントを正当化。
戻り値
文字列の長さを返します。
例
次の例では、使用するzfill()関数を示しています。
#!/usr/bin/python3 str = "this is string example from w3big....wow!!!" print ("str.zfill : ",str.zfill(40)) print ("str.zfill : ",str.zfill(50))
次のように上記の出力結果の例は次のとおりです。
str.zfill : this is string example from w3big....wow!!! str.zfill : 000000this is string example from w3big....wow!!!