maketrans() method is used for creating a translation table that can be used to perform character replacements or translations in strings. This method is particularly useful when there is a need to replace specific characters or substrings with other characters, or to remove certain characters from a string.
x: A string containing characters to be replaced.
y: A string containing characters with which
xneeds to be replaced.
z: A string containing characters to be deleted.
maketrans() method returns a translation table, which can then be used with the
translate() method to perform the actual translations or replacements in a string.
This example shows the use of
maketrans() method to replace characters in a string.
trans_table = str.maketrans('aeiou', '12345')str = "hello world"newstr = str.translate(trans_table)print(newstr)
This code will result in the following output:
The following code is runnable and uses the