python将字符串中多个空格换为一个空格 import re str = 'abc def gh ijk' strAfter = re.sub(' +', '', str) print(strAfter)