The replace() method returns a copy of the string where all occurrences of a substring are replaced with another substring.
#!/usr/bin/python3 # -*- coding: UTF-8 -*- str = "nice to meet you, have a nice day!" print( str) print( str.replace("nice", "good"))
nice to meet you, have a nice day! good to meet you, have a good day!
str.replace(old, new [, count])
|old||Old substring you want to replace|
|new||New substring which would replace the old substring|
It returns a copy of the string where the old substring is replaced with the new substring.