# 用正则import restr1 = 'hello wor ld \r\n'str2 = re.sub(r'\s', '', str1) # 正则'\s' 表示空白字符, 包括空格、\r\n\t等..print str2 # 输出 helloworld