python中用什么函数去掉空格

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


我们的服务
专业提供中小企业网站建设.公司网站建设.外贸网站建设.营销型网站建设,响应式网站建设,商城网站定制,手机网站,微信小程序定制.php应用开发服务,公司成立于2014年,8年专注网站建设,秉承“以客户为根本,以科技为核心,以市场为导向”的经营理念;服务电话13714666846(微信同号)

声明:本站所有作品(图文、音视频)均由用户自行上传分享,或互联网相关知识整合,仅供网友学习交流,若您的权利被侵害,请联系 管理员 删除。

本文链接:http://news.ew35.com/