python strip lstrip rstrip 用法

python中的strip用于去除字符串的首位字符,同理,lstrip用于去除左边的字符,rstrip用于去除右边的字符。

这三个函数都可传入一个参数,指定要去除的首尾字符。

需要注意的是,传入的是一个字符数组,编译器去除两端所有相应的字符

当没有传入参数时,是默认去除首尾空格的


string = 'say love me syas yaass'
>>> print string.strip()
say love me syas yaass
>>> print string.strip('say')
 love me syas 
>>> print string.lstrip('say')
 love me syas yaass
>>> print string.rstrip('say')
say love me syas 


你可能感兴趣的:(python strip lstrip rstrip 用法)