2022
我们一起努力

python中用什么函数去掉空格

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

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

string = " * it is blank space test * "print (string.lstrip())

输出结果为:

* it is blank space test *

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

string = "     * it is blank space test * "print (string.rstrip())

输出结果为:

       * it is blank space test *

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

string = " * it is blank space test * "print (string.strip())

输出结果为:

* it is blank space test *

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

string = " * it is blank space test * "str_new = string.replace(" ", "")print str_new

输出结果为:

*itisblankspacetest

赞(0)
文章名称:《python中用什么函数去掉空格》
文章链接:https://www.fzvps.com/29833.html
本站文章来源于互联网,如有侵权,请联系管理删除,本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
图片版权归属各自创作者所有,图片水印出于防止被无耻之徒盗取劳动成果的目的。

评论 抢沙发

评论前必须登录!