13518219792

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

创新互联Python教程:python如何去空格和回车?

python去掉空格和回车的方法:

1、使用strip()、lstrip()、rstrip()等方法删除字符串中的空格(这些方法只能删除字符串两端的空格)

 "   xyz   ".strip()            # returns "xyz"
 "   xyz   ".lstrip()           # returns "xyz   "
 "   xyz   ".rstrip()           # returns "   xyz"

2、使用replace()方法将空格替换为空

"  x y z  ".replace(' ', '') # returns "xyz"

3、使用replace("\n", "")方法将换行符替换为空。


网页名称:创新互联Python教程:python如何去空格和回车?
本文网址:http://cdbrznjsb.com/article/dhsiggo.html

其他资讯

让你的专属顾问为你服务