ReferenceString methods
str.replace()
Swaps every occurrence of one piece of text for another.
Signature
text.replace(old, new, count=-1)Parameters
| Name | Means |
|---|---|
old | what to look for |
new | what to put there |
count | how many to replace at most |
Returns
A new string.
Example
Python
print("one,two".replace(",", " | "))
print("aaa".replace("a", "b", 2))Output
one | two bba