Python字符串lstrip()
方法返回一个字符串的副本,其中指定字符(默认空白字符)从字符串的左侧删除。
语法
以下是lstrip()
方法的语法 -
str.lstrip([chars])
参数
- chars - 这是要修剪的字符。
返回值
- 此方法返回从字符串开头(左侧)删除所有指定字符(默认空白字符)后的字符串。
示例
以下示例显示了lstrip()
方法的用法。
#!/usr/bin/python3
## 删除左侧字符串:空格
str = " this is string example....wow!!!"
print (str.lstrip())
## 删除左侧字符串:*****
str = "*****this is string example....wow!!!*****"
print (str.lstrip('*'))
当运行上面的程序,它产生以下结果 -
this is string example....wow!!!
this is string example....wow!!!*****