How to remove a multiple characters from a string in Python

1 Answer

0 votes
def remove_chars(s, chars_to_remove): 
    if len(s)== 0: 
        return 'false'
   
    for ch in chars_to_remove:
        s = s.replace(ch, '')       
   
    return s
 
 
s ='python programming'
chars_to_remove ='pthm'
 
s = remove_chars(s, chars_to_remove)

print(s)

 
 
'''
run:
 
yon rograing
 
'''

 



answered Jan 16, 2020 by avibootz
edited Jan 17, 2020 by avibootz
...