0
Q:

maketrans and translate metods

# Python3 code to demostrate  
# translations using  
# maketrans() and translate() 
  
# specify to translate chars 
str1 = "wy"
  
# specify to replace with 
str2 = "gf"
  
# delete chars 
str3 = "u"
  
# target string  
trg = "weeksyourweeks"
  
# using maketrans() to  
# construct translate 
# table 
table = trg.maketrans(str1, str2, str3) 
  
# Printing original string  
print ("The string before translating is : ", end ="") 
print (trg) 
  
# using translate() to make translations. 
print ("The string after translating is : ", end ="") 
print (trg.translate(table)) 
0
The string before translating is : weeksyourweeks
The string after translating is : geeksforgeeks
0

New to Communities?

Join the community