Latest web development tutorials

Pythonのzfill()メソッド

Python文字列 Python文字列


説明

Pythonのzfill()メソッドは、元の文字列右寄せ、ゼロ詰めフロントの長さを指定する文字列を返します。

文法

zfill()メソッドの構文:

str.zfill(width)

パラメータ

  • 幅 - 文字列の長さを指定します。 元の文字列は右、ゼロ詰めフロントを正当化。

戻り値

文字列の長さを返します。

次の例では、使用する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文字列 Python文字列