去空格几种方法


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
————————————————
版权声明:本文为CSDN博主「因诺君」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_35868872/article/details/114411135


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM