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