As in 2.x, use str.replace().

Example:

>>> 'Hello world'.replace('world', 'Guido')
'Hello Guido'
Answer from Ignacio Vazquez-Abrams on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ Python โ€บ ref_string_replace.asp
Python String replace() Method
Remove List Duplicates Reverse ... Q&A Python Bootcamp Python Training ... The replace() method replaces a specified phrase with another specified phrase....
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ string-replace-method
Master Python's String Replace Method for Text Manipulation
In the Python programming languages, replace() is useful for replacing characters and other substrings within strings.
๐ŸŒ
StrataScratch
stratascratch.com โ€บ blog โ€บ how-to-replace-a-character-in-a-python-string
How to Replace a Character in a Python String - StrataScratch
October 18, 2024 - In this example, the string is converted to a list using split(). Then, the list comprehension part iterates over each word in the list. If it matches โ€˜blueโ€™, itโ€™s replaced with โ€˜redโ€™. If not, it keeps the original word.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-string-replace
Python String replace() Method - GeeksforGeeks
1 week ago - If omitted, all occurrences are replaced. Return Value: A new string with the specified replacements applied.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Replace Strings in Python: replace(), translate(), and Regex
May 4, 2025 - You can pass a dictionary to str.maketrans(), where each key is a single character to be replaced, and the corresponding value is the replacement string or None to remove it.
๐ŸŒ
Hyperskill
hyperskill.org โ€บ university โ€บ python โ€บ replace-method-in-python
Python replace() Method
July 17, 2024 - The Python replace method is a built-in string method used to replace occurrences of a given substring within a string with a new substring.
Find elsewhere
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ stdtypes.html
Built-in Types โ€” Python 3.14.6 documentation
Return a copy of the string with all occurrences of substring old replaced by new. If count is given, only the first count occurrences are replaced. If count is not specified or -1, then all occurrences are replaced.
๐ŸŒ
Real Python
realpython.com โ€บ replace-string-python
How to Replace a String in Python โ€“ Real Python
January 15, 2025 - ... You replace parts of a string in Python using the .replace() method, chaining it onto the string you want to modify and providing the method with two arguments: the string you want to replace and the replacement string.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ string_replace.htm
Python String replace() Method
The Python String replace() method replaces all occurrences of one substring in a string with another substring. This method is used to create another string by replacing some parts of the original string, whose gist might remain unmodified.
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 1493426 โ€บ how-to-replace-a-character-in-a-python-string
How to replace a character in a Python string? | Sololearn: Learn to code for FREE!
Function replace does it: https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/string_replace.htm In this case: a = "hey" print (a.replace('e','a'))
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-string-replace
Python String Replace Tutorial | DataCamp
June 25, 2020 - Python provides you with the .replace() string method that returns a copy of the string with all the occurrences of old substring replaced with the new substring given as a parameter.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ strings โ€บ .replace()
Python | Strings | .replace() | Codecademy
June 18, 2025 - In Python, the .replace() method replaces all occurrences of a specified substring with another substring in a string.
๐ŸŒ
Quora
quora.com โ€บ In-Python-how-do-I-use-the-replace-function-on-strings-to-replace-multiple-characters-e-g-a-space-or-any-special-character-with-the-empty-string-E-g-Tes-ting-replace-only-replaces-the-space-not-the
In Python, how do I use the .replace() function on strings to replace multiple characters, e.g. a space or any special character, with th...
Answer (1 of 4): Why do you ask how to use a function (method) to do something after youโ€™ve already demonstrated to yourself that the function/method doesnโ€™t do that? Perhaps itโ€™s better to describe what you want to accomplish and ask which functions or methods might already exist to ...
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ string.html
string โ€” Common string operations
The field_name is optionally followed by a conversion field, which is preceded by an exclamation point '!', and a format_spec, which is preceded by a colon ':'. These specify a non-default format for the replacement value. See also the Format specification mini-language section. The field_name itself begins with an arg_name that is either a number or a keyword. If itโ€™s a number, it refers to a positional argument, and if itโ€™s a keyword, it refers to a named keyword argument. An arg_name is treated as a number if a call to str.isdecimal() on the string would return true.
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ python string replace() | a detailed explanation!
Python String Replace() | A Detailed Explanation!
February 21, 2025 - Python string replace() method is a commonly used replacement method when working with Python strings. Other methods are loops, slicing, re.sub(), lists, etc.
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ python-replace-character-in-string
Python string.replace() โ€“ How to Replace a Character in a String - Flexiple - Flexiple
March 11, 2022 - The Python string.replace() method is a powerful tool for modifying strings by replacing a character, or sequence of characters, with a new character or sequence. This function is part of Python's string class, allowing developers to easily ...
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ string โ€บ replace
Python String replace()
If the old substring is not found, it returns a copy of the original string. ... # replacing 'cold' with 'hurt' print(song.replace('cold', 'hurt')) song = 'Let it be, let it be, let it be, let it be'