How to replace the first occurrence of a substring in a string with Python

1 Answer

0 votes
s = "aa bb cc dd ee cc"

result = s.replace("cc", "yy", 1)
print(result)


'''
run:
 
aa bb yy dd ee cc

'''

 



answered Nov 17, 2018 by avibootz
...