pythong中字符串strip的用法

strip的用法是去除字符串中前后两端的xx字符,xx是一个字符数组,并不是去掉“”中的字符串,

数组中包含的字符都要在字符串中去除。默认去掉空格,lstrip则是去掉左边的,rstrip是右边的

见代码:

In [1]: s = ' abc '

In [2]: s.strip()
Out[2]: 'abc'

In [3]: s = 'abc def abc'

In [4]: s.strip()
Out[4]: 'abc def abc'

In [5]: s.strip('abc')
Out[5]: ' def '

In [6]: s.strip('ab')
Out[6]: 'c def abc'

  

In [7]: s.lstrip('ab')
Out[7]: 'c def abc'

In [8]: s.rstrip('ab')
Out[8]: 'abc def abc'

  

原文地址:https://www.cnblogs.com/wswang/p/5465577.html