python中lstrip怎么使用
lewis
2017-11-06
20次阅读
在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()函数只能去除字符串开头的字符,并不会对字符串中间或结尾的字符进行操作。

发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。