Hello dear readers! Welcome back to another edition of our tutorial on Python. In this tutorial guide, we are going to be discussing about the String maketrans() method in Python.
The Python string maketrans() method returns a translation table which 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.
Note - Both intab and outtab has same length.
The Python string maketrans() method returns a translation table which 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.
Note - Both intab and outtab has same length.
Syntax
The following below is the syntax for the Python String maketrans() method -
str.maketrans(intab, outtab)
RECOMMENDED POST: Python String lstrip() Method
Parameter Details
- intab - It is the string having actual characters.
- outtab - A string having corresponding characters.
Return Value
Returns a translate table.
Example
The following below is a simple 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
Below is the output of the above example -
th3s 3s str3ng 2x1mpl2....w4w!!!
RECOMMENDED POST: Python String isnumeric() Method
Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the Python String max() method.
Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.