String Methods
maketrans()
Create a translation table for use with translate().
str.maketrans(x, y=None, z=None)
Create a table that tells translate() how to change characters.
Call it on str, then pass the table to a string's translate() method.
Parameters
| Name | Description |
|---|---|
| x | A mapping, or a string of characters to translate. |
| y | When x is a string, replacement characters of the same length. |
| z | Optional characters to delete. |
Returns
A dictionary suitable for str.translate().
Try it
Run it and change it
table = str.maketrans("abc", "123")
print("abc".translate(table))