strip() 、lstrip() 、rstrip()

strip() 用于移除字符串开头和结尾的空格或换行符,如果指定参数,则表示移除指定的字符
lstrip() 用于移除字符串开头的空格或换行符,如果指定参数,则表示移除指定的字符
rstrip() 用于移除字符串结尾的空格或换行符,如果指定参数,则表示移除指定的字符

In [1]: str = '  hello world  '

In [2]: str.strip()
Out[2]: 'hello world'

In [3]: str.lstrip()
Out[3]: 'hello world  '

In [4]: str.rstrip()
Out[4]: '  hello world'

In [6]: str.strip('d  ')
Out[6]: 'hello worl'

 

 

 

 

 

 

      

posted @ 2019-01-17 09:14  孔雀东南飞  阅读(197)  评论(0编辑  收藏  举报