Home >Backend Development >Python Tutorial >How to replace a specified string in python
In python, you can use the replace() method of string
to replace the specified string. This method accepts two parameters, the first parameter is the string to be replaced, and the second parameter is the replaced string. Here is an example:
string = "Hello, World!" new_string = string.replace("World", "Python") print(new_string)
The output result is:
Hello, Python!
In this example, we replace "World" in the string Hello, World!
with "Python" and print the result.
The above is the detailed content of How to replace a specified string in python. For more information, please follow other related articles on the PHP Chinese website!