扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

python中lstrip怎么使用

扬州沐宇科技
2023-11-13 11:56:06
python

在Python中,lstrip()函数可以用于去除字符串开头的指定字符或字符序列。它的使用方法如下:

  1. 去除开头的空格:
str1 = "   hello world"
result = str1.lstrip()
print(result)  # 输出:hello world
  1. 去除开头的指定字符或字符序列:
str2 = "###hello world"
result = str2.lstrip("#")
print(result)  # 输出:hello world

str3 = "abcabcabc123"
result = str3.lstrip("abc")
print(result)  # 输出:123

注意:lstrip()函数只能去除字符串开头的字符,并不会对字符串中间或结尾的字符进行操作。

扫码添加客服微信