replace a substring in string python code example
Example 1: python replace substring
txt = "I like bananas"
x = txt.replace("bananas", "apples")
print(x) # ----> I like apples
Example 2: python replace string
string.replace(old, new, count)
txt = "I like bananas"
x = txt.replace("bananas", "apples")
print(x) # ----> I like apples
string.replace(old, new, count)