Python String translate() Syntax

str.translate(translation_table)

Example:

In the given example, we are using str.translate() method is used to translate a string by specifying a mapping using ASCII values.

Python3




# specifying the mapping using ASCII 
translation = {103: None, 101: None, 101: None}
 
string = "geeks"
 
# translate string
print("Translated string:",
       string.translate(translation))


Output: 

Translated string: ks

Python String translate() Method

Python String translate() returns a string that is a modified string of givens string according to given translation mappings. 

Similar Reads

What is translate() in Python?

translate() is a built-in method in Python that is used to replace specific characters in a string with other characters or remove them altogether. The translate() method requires a translation table that maps the characters to be replaced to their replacements. This table can be generated using the maketrans() method, which takes two arguments: the characters to be replaced and their replacements....

Python String translate() Syntax

str.translate(translation_table)...

Python String translate() Examples

...

Python maketrans()

There are two ways to translate are:...

Python maketrans() Syntax

...

Use case of translate() and maketrans() Method

...