#必须替换的与被替换的必须一一对应
intab = "inedmor"
outtab = "1234567"
str_trantab = str.maketrans(intab,outtab)
test_str = "i need more courage to touch you"
print(test_str.translate(str_trantab))
结果:
1 2334 5673 c6u7ag3 t6 t6uch y6u
#必须替换的与被替换的必须一一对应
intab = "inedmor"
outtab = "1234567"
str_trantab = str.maketrans(intab,outtab)
test_str = "i need more courage to touch you"
print(test_str.translate(str_trantab))
结果:
1 2334 5673 c6u7ag3 t6 t6uch y6u