新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonlstrip()
python 中的lstrip()函數(shù)根據(jù)給定的參數(shù)刪除原始字符串副本中的前導字符。方法將此副本作為輸出返回。

**string.lstrip([chars])** #where chars are those to remove as leading characters
lstrip()參數(shù):
函數(shù)的作用是:以字符為參數(shù)。如果未提供字符,則從字符串中刪除前導空格。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 燒焦 | 要作為前導字符移除的字符 | 可選擇的 |
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-$$$$ 網(wǎng)頁名稱:創(chuàng)新互聯(lián)Python教程:Pythonlstrip()
網(wǎng)頁鏈接:http://www.dlmjj.cn/article/djshdec.html


咨詢
建站咨詢
