1 a = ‘hello world‘ 2 a.replace(‘ ‘, ‘‘) 3 # ‘helloworld‘
1 a = ‘‘.join(a.split()) 2 print(a) 3 # helloworld
1 import re 2 strinfo = re.compile() 3 strinfo = re.compile(‘ ‘) 4 5 b = strinfo.sub(‘‘, a) 6 print(b) 7 # helloworld
content = input("请输入内容:").strip() #可输入1 + 3 # print(‘‘.join(content.split())) index = content.find("+") a = content[0:index] b = content[index+1:] print(int(a)+int(b)) #转化以后,自动去除空格
原文:https://www.cnblogs.com/shihaoyu/p/9862208.html