How to replace only 2 occurrence of word in string with Python

1 Answer

0 votes
s = 'Python Java Python C Java Python C++'

s = s.replace('Python', 'Pro', 2)
  
print(s)
  
  
  
'''
run:
  
Pro Java Pro C Java Python C++
 
'''

 



answered Sep 1, 2021 by avibootz
...