Python String translate Method

The Python translate function processes a string where each character has been substituted according to a specified translation table. To generate this translation map, we can utilize the maketrans method, which allows for the creation of mappings between characters in various formats.

Signature

Example

translate(table)

Parameters

table : A translation table.

Return

It returns a string.

Let’s explore a few instances of the translate method to grasp its functionality more thoroughly.

Python String translate Method Example 1

Example

# Python translate() method
# Declaring table and variables
table = { 97 : 103, 111 : 112, 117 : None }
str = "Hello logicpractice"
# Calling function
str2 = str.translate(table)
# Displaying result
print(str2)

Output:

Output

Hellp jgvgtppint

Input Required

This code uses input(). Please provide values below: