How to replace all occurrences of a substring in a string with Python

1 Answer

0 votes
s = 'java python java java php java'
  
temp = str.maketrans("java", "WORD") 

s = s.translate(temp) 
  
print(s) 


        
'''
run:
 
WDRD python WDRD WDRD php WDRD
        
'''

 



answered Apr 30, 2020 by avibootz
...