String Methods
translate()
Replace or remove characters according to a translation table.
str.translate(table)
Replace or remove characters according to a translation table.
Arguments
Parameters
| Name | Description |
|---|---|
| table | A mapping from character code points to replacement text, code points, or None. |
Result
Returns
A new translated string.
Run it
Try it
Run it and change it
table = str.maketrans("abc", "123")
print("cab".translate(table)) Output
Press Run to see what it prints.