传入参数x,y,z
当传入一个参数既x时:
transtab = str.maketrans({'a':'b'})
news = 'apple'
print (news.translate(transtab))
必须使用字典传入参数而且字典只能为整数或者一个字符
当传入两个参数时:
transtab = str.maketrans('ap','bs')
news = 'apple'
print (news.translate(transtab))
这时就可以随意映射,注意x,y必须具有相同字节数
当传入三个参数时:
transtab = str.maketrans('ap','bs','al')
news = 'apple'
print (news.translate(transtab))
》》sse
当z中有与x中重复的x优先映射到None有与映射后相同的将相同的映射结果变成None
z字节数可以与x,y不一致
下面是原描述:
str.maketrans(x, y, z)
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.