1、使用字符串函数replace >>> a = 'hello world' >>> a.replace(' ', '') 'helloworld' 2、使用字符串函数split >>> a = ''.join(a.split()) >>> print(a) helloworld