About Lesson
replace():-
The replace() method replaces a specified phrase with another specified phrase.
Syntax:- string.replace(oldvalue, newvalue, count)
txt = “I like bananas” x = txt.replace(“bananas”, “apples”) print(x) Output I like apples |
txt = “one one was a race horse, two two was one too.” x = txt.replace(“one”, “three”) print(x) Output three three was a race horse, two two was three too. |
txt = “one one was a race horse, two two was one too.” x = txt.replace(“one”, “three”, 2) print(x) Output three three was a race horse, two two was one too. |