Course
Simulator
More
Premium
Log in
Python Function Reference
Functions
replace
replace
Return a copy of the string with all occurrences of substring old replaced by new.
Python 3.13
1
str
.
replace
(
old
,
new
,
count
=
-
1
)
old
The old substring to be replaced.
new
The new substring.
count
How many occurrences to replace.
Examples
Python 3.13
1
'hello world'
.
replace
(
'world'
,
'Python'
)
'hello Python'