- 方法一
new_str = "".join(str.split())
方法二
使用正则
import re
params = re.compile("\s+") #匹配任意空白字符,等价于 [\t\n\r\f].
new_string = re.sub(params,'',str)
print(new_string)
new_str = "".join(str.split())
方法二
使用正则
import re
params = re.compile("\s+") #匹配任意空白字符,等价于 [\t\n\r\f].
new_string = re.sub(params,'',str)
print(new_string)