s = 'one two one two one' print(s.replace('one', 'XXX')) # Output - # XXX two XXX two XXX s = 'one two one two one' print(s.replace('one', 'XXX', 2)) # 2 is the number of count # Output - # XXX two XXX two one