Important Notice:

Course Content
The Calendar Module
Library Function/Predefined Functions
0/4
Sys Module
Library Function/Predefined Functions
0/2
OS Module
Library Function/Predefined Functions
0/2
Functions in Python (Chapter-10) M3-R5
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.

error: Content is protected !!