How to Use String replace() Function
You can easily use the replace() function, you just need to call the function with a string object and pass the strings as a parameter. The first parameter is the substring you want to replace, and the second parameter is the string you want to replace with.
Let’s understand it better how to replace a string in Python with a simple example:
Python3
string = "Replace" new_string = string.replace( "Replace" , "Replaced" ) print (new_string) |
Replaced
Python String replace() Method
The string replace() method returns a copy of the string where occurrences of a substring are replaced with another substring.
Example:
Python3
string = "Hello World" new_string = string.replace( "Hello" , "Good Bye" ) print (new_string) |
Good Bye World