Python 字符串 lstrip() 方法

实例

删除字符串左侧的空格:

  1. txt = " banana "
  2.  
  3. x = txt.lstrip()
  4.  
  5. print("of all fruits", x, "is my favorite")

定义和用法

lstrip() 方法删除所有前导字符(空格是要删除的默认前导字符)。

语法

  1. string.lstrip(characters)

参数值

参数 描述
characters 可选。一组作为前导字符要删除的字符。

更多实例

实例

删除前导字符:

  1. txt = ",,,,,ssaaww.....banana"
  2.  
  3. x = txt.lstrip(",.asw")
  4.  
  5. print(x)