pythonのlstrip関数の使い方は?
Pythonでは、lstrip()関数は、文字列の左端から指定した文字や文字列を取り除くのに使います。使い方は次のとおりです。
- 先頭の空白文字を削除します
str1 = " hello world"
result = str1.lstrip()
print(result) # 输出:hello world
- 先頭の指定した文字または文字列を除去する:
str2 = "###hello world"
result = str2.lstrip("#")
print(result) # 输出:hello world
str3 = "abcabcabc123"
result = str3.lstrip("abc")
print(result) # 输出:123
lstrip()関数は文字列の始めの文字しか削除できず、文字列の途中や末尾の文字には適用されません。