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
- replace() in Python to replace a substring
- Program to replace a word with asterisks in a sentence
- String slicing in Python to check if a string can become empty by recursive deletion
- String slicing in Python to rotate a string
- String Alignment in Python f-string
- Pad or fill a string by a variable in Python using f-string
- Python | String startswith()
- Python string | strip()
- Python program to split and join a string
- Python String isspace() and its application
- Python String index() and its applications
- Python String isalpha() and its application
- Python code to move spaces to front of string in single traversal
- Python String isdigit() and its application
- Python Regex to extract maximum numeric value from a string
- Find the first repeated word in a string in Python using Dictionary
- Concatenated string with uncommon characters in Python
- Python counter and dictionary intersection example (Make a string using deletion and rearrangement)
- Python | Swap commas and dots in a String
- Python | Program to convert String to a 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.
Improved By : nidhi_biet