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

1 Answer

0 votes
s = "aa bb cc dd ee cc, ff, gg, cc"

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


'''
run:
 
aa bb yy dd ee yy, ff, gg, cc

'''

 



answered Nov 17, 2018 by avibootz
...