replace() - Returns a string where a specified value is replaced with a specified value

By default, replaces all occurrences of the substring with a new string.  The number of occurrences can also be specified.


str = 'The quick brown fox jumped over the lazy dog'
print(str.replace('fox', 'cow'))
str = 'Hello World'
print(str.replace('o', 'ow', 1)) # replace just the first occurrence of the letter 'o'


The quick brown cow jumped over the lazy dog
Hellow World