How to Replace a String with Another String in Python


In this example, we will learn how to replace a string with another string using the replace() method in Python.

Source Code

my_str = 'I love Python'

print(my_str)
print(my_str.replace('I', 'We'))

Output:

I love Python
We love Python
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments