replace() is an inbuilt function in Python programming language that returns a copy of the string where all occurrences of a substring is replaced with another substring.
string.replace(old, new, count)
old – old substring you want to replace.
new – new substring which would replace the old substring.
count – the number of times you want to replace the old substring with the new substring. (Optional )
Return Value :
It returns a copy of the string where all occurrences of a substring is replaced with another substring.
Below is the code demonstrating replace() :
Geeks for Geeks Geeks Geeks Geeks GeeksforGeeks for GeeksforGeeks GeeksforGeeks geeks geeks
- Python String Methods | Set 3 (strip, lstrip, rstrip, min, max, maketrans, translate, replace & expandtabs())
- replace() in Python to replace a substring
- Python | Pandas Series.str.replace() to replace text in a series
- Python | Pandas Timestamp.replace
- Python | Pandas Series.replace()
- Python | Replace multiple characters at once
- Python | Pandas dataframe.replace()
- Python | Replace negative value with zero in numpy array
- Python | Replace substring in list of strings
- Python | Replace NaN values with average of columns
- Python | Replace multiple occurrence of character by single
- Python | Replace list elements with its ordinal number
- Map function and Lambda expression in Python to replace characters
- Python | Pandas DataFrame.fillna() to replace Null values in dataframe
- Python | Replace elements in second list with index of same element in first list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.