At times we need to replace strings in a statement or in a file. We will see here how we can replace a string with another in python.
To Replace a string in python, we can user replace() method.
Example:
old_string = "This is the old string."
new_string = old_string.replace("old", "new")
print(new_string)
Code: