Skip to content
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

NameDescription
xA mapping, or a string of characters to translate.
yWhen x is a string, replacement characters of the same length.
zOptional 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))

Related entries