str.replace()
str.replace() is a Python method in the String Methods category. Returns a copy with occurrences of `old` replaced by `new` (optionally limited to `count`). The syntax is str.replace(old, new, count=-1). Parameters: old, new — substrings. Returns: Replaced string. A typical example: "hello world".replace("l", "x") # "hexxo worxd"
"aaa".replace("a", "b", 2) # "bba". A close sibling is str.upper(), which returns a copy of the string with all characters converted to uppercase. A close sibling is str.lower(), which returns a copy of the string with all characters converted to lowercase. A close sibling is str.capitalize(), which returns a copy with the first character capitalized and the rest lowercased. A close sibling is str.title(), which returns a titlecased version where each word starts with uppercase. More about this category: String methods for text manipulation — split, join, replace, format, and more. For a broader walkthrough, read the String Methods guide.