Replace String Method in Python

  • Post category:String

In this article, you will see how to use the replace string method in Python. The string replace means replacing a substring with another substring. In Python, you can use the replace() method to replace a substring with another substring. The following code shows how to replace a substring with another substring in Python.

Step 1: Create a string

str = "CodeAllow"
print("str = ", str)
print("str type = ", type(str))

Step 2: Replace string

print("Replaced = ", str.replace("Code", "Python"))

Output:

str =  CodeAllow
str type =  <class 'str'>
Replaced =  PythonAllow

Free resources to learn advanced skills: AiHints and CodeAllow