Skip to content
String Methods

translate()

Replace or remove characters according to a translation table.

str.translate(table)

Replace or remove characters according to a translation table.

Parameters

NameDescription
tableA mapping from character code points to replacement text, code points, or None.

Returns

A new translated string.

Try it

Run it and change it
table = str.maketrans("abc", "123")
print("cab".translate(table))

Related entries