去掉字符串中的单的方法就是使用replace()方法 语法:str.replace(old, new[, max]) a="hello this word" a=a.replace(" ","") print(a) 运行结果: