To replace a substring in a string in Python, you can use the `replace()` method or regular expressions.
In this example,
str
with a value of "Hello World"
.replace()
method to replace the substring "World"
with "Universe"
.str
.str = "Hello World"
str = str.replace("World", "Universe")
print(str)
Hello Universe
In this tutorial, we learned How to Replace a Substring in String in Python language with well detailed examples.