What is String replace() Method?
String replace() is a built-in function in Python and it is used to replace a substring with another string. It will replace every occurrence of that substring, so it should be used with caution.
It does not change the original string but returns a new one. It is mostly used in string substitution.
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