Python-string-strip

提供:Dev Guides
移動先:案内検索

Python String strip()メソッド

説明

Python文字列メソッド* strip()*は、すべての文字が文字列の先頭と末尾から取り除かれた文字列のコピーを返します(デフォルトの空白文字)。

構文

以下は* strip()*メソッドの構文です-

str.strip([chars]);

パラメーター

  • chars -文字列の先頭または末尾から削除される文字。

戻り値

このメソッドは、文字列の先頭と末尾からすべての文字が削除された文字列のコピーを返します。

次の例は、strip()メソッドの使用方法を示しています。

#!/usr/bin/python

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

上記のプログラムを実行すると、次の結果が生成されます-

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