![图片[1]-python如何去空格和回车?-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5ecb660c40c24269.jpg)
python去掉空格和回车的方法:
1、使用strip()、lstrip()、rstrip()等方法删除字符串中的空格(这些方法只能删除字符串两端的空格)
"xyz".strip()#returns"xyz" "xyz".lstrip()#returns"xyz" "xyz".rstrip()#returns"xyz"
2、使用replace()方法将空格替换为空
"xyz".replace('','')#returns"xyz"
3、使用replace("\n", "")方法将换行符替换为空。
原文来自:https://www.py.cn© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
















































暂无评论内容