Python string maketrans() method returns a mapping table that maps every character in the intab string in the same place in the outtab string. This table is then moved to the translate() function.
The syntax of the method is: str.maketrans(intab, outtab]);
Key Points :
• The maketrans() method acts as a translate() support method.
• The maketrans() method primarily returns a mapping table used by the translate() method for more translation.
• A static method used to map characters in a string to their replacement characters from one to one.
• This method helps to establish a Unicode representation for the translation of each character.
Below is the python program to demonstrate the maketrans() function:
intab = "aeiou" outtab = "*#@!~" trantab = str.maketrans(intab, outtab) str = "The Best Learning Resource for Online Education"; print (str.translate(trantab))
When we run above the program, the outcome is as follows:
Th# B#st L#*rn@ng R#s!~rc# f!r Onl@n# Ed~c*t@!n
Below are several other functions that we can use to work with string in Python 3