sub()函数将匹配项替换为您选择的文本:将每个空格字符替换为数字 8:import retxt = "The glass in table"x = re.sub("\s", "8", txt)print(x)执行结果:The8glass8in8table