The maketrans() function is a method available in Python's string methods. It is used to create a translation table that maps one set of characters to another set. This method is often used in conjunction with the translate() method to replace characters in a string efficiently.
Parameter Values
| Parameter | Description |
|---|---|
| x | A string specifying the characters that need to be replaced. |
| y | A string specifying the replacement characters. |
Return Values
The maketrans() method returns a translation table usable for str.translate().
How to Use maketrans() in Python
Example 1:
The maketrans() method returns a translation table that maps one set of characters to another.
translation_table = str.maketrans('aeiou', '12345')
print(translation_table)