RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
创新互联Python教程:Pythonlstrip()

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-$$$$ 

分享文章:创新互联Python教程:Pythonlstrip()
浏览路径:http://www.jxjierui.cn/article/djshdec.html