Python3 string.lstrip()方法

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!!!*****

上一篇: Python3数字 下一篇: Python3字符串