str.maketrans()方法接受一个或两个参数, 返回一个字典(字典的 key 和 value 均用unicode编码)
1.接受两个参数
str.maketrans(str1, str2)
str1, str2均为字符串, 将 str1 和 str2 的元素按次序关系构造成字典, 字典的 key 和 value 均用unicode编码.
intable = "aeiou"
outtable = "12345"
trantab = str.maketrans(intable, outtable)
返回
trantab: {97: 49, 101: 50, 105: 51, 111: 52, 117: 53}
2.接受一个参数
str.maketrans(dict1)
dict1 为一个字典, 返回一个字典(字典的 key 和 value 均用unicode编码).
parentheses_table = str.maketrans({"(": None, ")": None})
parentheses_table: {40: None, 41: None}