translate针对的是单个字符,而replace是字符串
例如
translate = {
"I": 1,
"V": 5,
"X": 10,
"L": 50,
"C": 100,
"D": 500,
"M": 1000
}
s = s.replace("CD", "CCCC").replace("CM", "DCCCC")
在SQL中
SELECT translate('afetghtabc','abc','h') FROM table1
输出结果为 hfetghth
SELECT replace('afetghtabc','abc','h')FROM table1
输出结果为 afetghth