All String methods

translate() , maketrans() : Search replace and delete of set of chars.
str_search : Required, Chars to be searched
str_replace: Required, Chars to be replaced ( mapped to searched chars )
str_delete : Optional, Chars to be replaced with None ( deleted in final string )

Length of str_search should be equal to length of str_replace
the method maketrans() returns a dictionary ( str_update ) with chars mapped for search and replace and this can be used for translate().
str_search='abc'  # search chars 
str_replace='xyz' # replace chars 
str_delete='pqr'  # delete chars 

str_input='abcdefghpqr' #input string 


print(str_update) # dictionary output with chars mapped. 
print("input string : ",str_input)
print("Output string: ",str_input.translate(str_update))
{97: 120, 98: 121, 99: 122, 112: None, 113: None, 114: None}
input string :  abcdefghpqr
Output string:  xyzdefgh
All String methods

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer