Latest web development tutorials

Pythonのストリップ()メソッド

Python文字列 Python文字列


説明

Pythonのストリップ()メソッドは、(デフォルトではスペース)指定された文字列の先頭と末尾を削除するために使用されます。

文法

ストリップ()メソッドの構文:

str.strip([chars]);

パラメータ

  • 文字 - 指定した文字列の先頭と末尾を削除します。

戻り値

ヘッドを取り外し、末尾の文字列は、新しい文字列指定された文字の生成を返します。

次の例では、使用するストリップ()関数を示しています。

#!/usr/bin/python

str = "0000000this is string example....wow!!!0000000";
print str.strip( '0' );

次のように上記の出力結果の例は次のとおりです。

this is string example....wow!!!

Python文字列 Python文字列