You are here : python_2stringstringmaketrans

string.maketrans() - string

             

The method maketrans() returns a translation table that maps each character in the intabstring into the character at the same position in the outtab string. Then this table is passed to the translate() function.


  • intab -- This is the string having actual characters.

  • outtab -- This is the string having corresponding mapping character.


Syntax

str.maketrans(intab, outtab)


Example

#!/usr/bin/python

from string import maketrans   # Required to call maketrans function.

intab = "aeiou"
outtab = "12345"
trantab = maketrans(intab, outtab)

str = "this is string example....wow!!!"
print str.translate(trantab)


Output / Return Value

When we run above program, it produces following result −


th3s 3s str3ng 2x1mpl2....w4w!!!


Limitations


Alternatives / See Also


Reference