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'

 

 

 

 

 

 

      

相关文章:

  • 2021-08-20
  • 2021-07-25
  • 2021-06-08
  • 2022-01-28
  • 2021-09-15
  • 2022-12-23
  • 2021-12-12
  • 2021-12-13
猜你喜欢
  • 2021-10-10
  • 2021-10-01
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2021-11-22
相关资源
相似解决方案