Python 字符串 lstrip() 方法
实例
删除字符串左侧的空格:
- txt = " banana "
- x = txt.lstrip()
- print("of all fruits", x, "is my favorite")
定义和用法
lstrip() 方法删除所有前导字符(空格是要删除的默认前导字符)。
语法
- string.lstrip(characters)
参数值
参数 | 描述 |
---|---|
characters | 可选。一组作为前导字符要删除的字符。 |
更多实例
实例
删除前导字符:
- txt = ",,,,,ssaaww.....banana"
- x = txt.lstrip(",.asw")
- print(x)