首页>>帮助中心>>香港云服务器python中用什么函数去掉空格

香港云服务器python中用什么函数去掉空格

2023/5/26 527次

香港云服务器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

一诺网络香港免备案专区,提供「香港增强云服务器」和「香港特惠云服务器」两种类型的高可用弹性计算服务,搭载新一代英特尔®至强®铂金处理器,接入CN2低延时高速回国带宽线路,网络访问顺滑、流畅。机房网络架构采用了BGP协议的解决方案可提供多线路互联融合网络,使得不同网络运营商线路的用户都能通过最佳路由实现快速访问。香港云服务器低至29元/月,购买链接:https://www.enuoidc.com/vps.html ?typeid=2