Python str.replace() Method
The replace() method replaces a specified phrase with another
specified phrase.
Syntax
string.replace(oldvalue, newvalue, count)
Parameters
| Parameter | Description |
|---|---|
oldvalue |
Required. The string to search for |
newvalue |
Required. The string to replace the old value with |
count |
Optional. A number specifying how many occurrences of the old value you want to replace. Default is all occurrences |
Return Value
A copy of the string where all occurrences of a substring are replaced.
Example
Using the replace() method:
Output
Click Run to execute your code
Enjoying these tutorials?