The translate() method returns a string. In this string, each character is mapped to its corresponding character in the translation table.
#!/usr/bin/python3 # -*- coding: UTF-8 -*- intab = "this!" outtab = "THIS?" trantab = str.maketrans(intab, outtab) # make translation table str = "this is an example....wow!!!" print(str.translate(trantab))
THIS IS an example....wow???
|table||A translation table which contains the mapping between two characters.|
It returns a string where each character is mapped to its corresponding character as per the translation table.