Linux 拨号vps windows公众号手机端

python中用什么函数去掉空格

lewis 6年前 (2019-03-17) 阅读数 11 #程序编程
文章标签 python

python中去掉空格的方法有以下几种

1.使用lstrip()函数去掉左边空格

string="*itisblankspacetest*"print(string.lstrip())

输出结果为:

*itisblankspacetest*

2.使用rstrip()函数去掉右边空格

string="*itisblankspacetest*"print(string.rstrip())

输出结果为:

*itisblankspacetest*

3.使用strip()函数去掉左右两边空格

string="*itisblankspacetest*"print(string.strip())

输出结果为:

*itisblankspacetest*

4.使用replace()函数去掉所有空格

string="*itisblankspacetest*"str_new=string.replace("","")printstr_new

输出结果为:

*itisblankspacetest


版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门