import restring = "Hello 123 World 456"new_string = re.sub("d", "#", string)print(new_string) # 输出:Hello ### World ###