Python3-string-lstrip

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

Python 3-ストリングlstrip()メソッド

説明

  • lstrip()*メソッドは、文字列(デフォルトの空白文字)の先頭からすべての文字が削除された文字列のコピーを返します。

構文

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

str.lstrip([chars])

パラメーター

*chars* -トリミングする必要のある文字を指定できます。

戻り値

このメソッドは、文字列の先頭からすべての文字が削除された文字列のコピーを返します(デフォルトの空白文字)。

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

#!/usr/bin/python3

str = "     this is string example....wow!!!"
print (str.lstrip())

str = "*****this is string example....wow!!!*****"
print (str.lstrip('*'))

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

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