Fork me on GitHub

Python lstrip() 方法

描述

Python lstrip() 方法用于删除字符串头部指定的字符,默认字符为所有空字符,包括空格、换行(\n)、制表符(\t)等。

语法

lstrip() 方法语法:

S.lstrip([chars])

参数

  • chars -- 可选参数,要删除的指定字符,默认字符为所有空字符,包括空格、换行(\n)、制表符(\t)等。

返回值

返回删除字符串头部指定的字符后生成的新的字符串。

实例

以下实例展示了 lstrip() 方法的使用方法:

#!/usr/bin/python3

S = "     this is string example....wow!!!     ";
print( S.lstrip() );
S = "88888888this is string example....wow!!!8888888";
print( S.lstrip('8') );

以上实例输出结果如下:

this is string example....wow!!!     
this is string example....wow!!!8888888
posted @ 2017-10-18 15:36  IT技术随笔  阅读(1809)  评论(0编辑  收藏  举报
返回顶部↑