The following example shows how the translate () function is used:
#!/usr/bin/python from string ImportMaketrans# Refer to the Maketrans function. Intab= "Aeiou"Outtab= "12345"Trantab=Maketrans(Intab,Outtab)Str= "This is string EXAMPLE....WOW!!!";PrintStr.Translate(Trantab);
The result of the above example output is as follows:
th3s3sStr3ng2x1mpl2....w4w!!!
The above example removes the ' x ' and ' m ' characters from the string:
#!/usr/bin/python from string ImportMaketrans# Required to call Maketrans function.Intab= "Aeiou"Outtab= "12345"Trantab=Maketrans(Intab,Outtab)Str= "This is string EXAMPLE....WOW!!!";PrintStr.Translate(Trantab, ' XM ');
The result of the above example output:
th3s3sStr3ng21pl2....w4w!!!
Source: http://www.runoob.com/python/att-string-translate.html
From for notes (Wiz)
How to use the translate () function