Home  >  Article  >  Backend Development  >  python中去空格函数的用法

python中去空格函数的用法

WBOY
WBOYOriginal
2016-06-16 08:42:421556browse

本文简单介绍了Python中去空格函数的用法,这是一个很实用的函数,希望对大家的Python程序设计有所帮助。具体分析如下:

在Python中字符串处理函数里有三个去空格的函数:

strip 同时去掉左右两边的空格
lstrip 去掉左边的空格
rstrip 去掉右边的空格

具体示例如下:

>>>a=" gho stwwl "
>>>a.lstrip()
'gho stwwl '
>>>a.rstrip()
' gho stwwl'
>>>a.strip()
'gho stwwl'

感兴趣的朋友可以测试一下上述实例代码,以加深对函数用法的印象。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn