python 字符串去除空格

记录一下,测试工作遇到的问题是:没有对输入框的输入的内容去除空格    以下链接是前端去除空格的方式

https://www.cnblogs.com/xiaoniuniu886/p/10609644.html

 

自己用python实现了下,如下

import re
str=" 1 11 11 "
print("---"+str.strip()+"---")#去除前后的空格
print("---"+str.lstrip()+"---")#去除左边的空格
print("---"+str.rstrip()+"---")#去除右边的空格
print("---"+str.replace(" ","")+"---")#去除全部空格
print("---"+re.sub(r"\s+", "", str)+"---")##去除全部空格

 

posted @ 2021-11-17 15:55  eosclover  Views(347)  Comments(0Edit  收藏  举报