Python3 zfill()メソッド

Python3 字符串Python3 文字列


説明

Python zfill() メソッドは、指定した長さの文字列を返します。元の文字列は右寄せされ、前に0が埋められます。

構文

zfill()メソッドの構文:

str.zfill(width)

パラメータ

  • width -- 文字列の長さを指定します。元の文字列は右寄せされ、前に0が埋められます。

戻り値

指定された長さの文字列を返します。

例

以下の例は、zfill()関数の使用方法を示しています。

#!/usr/bin/python3

str = "this is string example from サンプル....wow!!!"
print ("str.zfill : ",str.zfill(40))
print ("str.zfill : ",str.zfill(50))

上記の例の出力結果は次のとおりです:

str.zfill :  this is string example from サンプル....wow!!!
str.zfill :  000000this is string example from サンプル....wow!!!

Python3 字符串Python3 文字列

その他の拡張