python 中的lstrip()
函數根據給定的參數刪除原始字符串副本中的前導字符。方法將此副本作為輸出返回。
**string.lstrip([chars])** #where chars are those to remove as leading characters
lstrip()
參數:
函數的作用是:以字符為參數。如果未提供字符,則從字符串中刪除前導空格。
參數 | 描述 | 必需/可選 |
---|---|---|
燒焦 | 要作為前導字符移除的字符 | 可選擇的 |
lstrip()
返回值
返回值始終是字符串。在找到第一個匹配之前,所有字符組合都從左邊開始刪除。
| 投入 | 返回值 | | 線 | 字符串的副本 |
Python 中lstrip()
方法的示例
示例lstrip()
在 Python 中是如何工作的?
# Variable declaration
string1 = " Python "
# Leading whitepsace are removed
print(string1.lstrip())
string2 = ",,,,,ssaaww.....programming"
print(string2.lstrip(",.asw"))
輸出:
Python
programming
例 2:伊斯特普的工作
# Variable declaration
string1 = "$$$$-Python-$$$$"
# Calling function
string2 = string1.lstrip('$')
# Displaying result
print(string1)
print(string2)
輸出:
$$$$-Python-$$$$
-Python-$$$$