功能 str.replace() 不改变调用它的字符串-它不能,字符串是不可变的-它返回新字符串。不将输出保存到变量,因此它将丢失。
str.replace()
你需要交换 string.replace(exception_char, exception_chars_dict[exception_char]) 对于 string = string.replace(exception_char, exception_chars_dict[exception_char]) .
string.replace(exception_char, exception_chars_dict[exception_char])
string = string.replace(exception_char, exception_chars_dict[exception_char])