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

python中去空格函数的用法

WBOY
Release: 2016-06-16 08:42:42
Original
1603 people have browsed it

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

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

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

具体示例如下:

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

Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template