Reputation: 35
I am learning python ,i.e., version 3.8 While trying to replace a string substring using replace() function.
str = "Python"
str.replace("th", "t")
print(str)
Output: Python
Expected Output: Pyton
Upvotes: 0
Views: 93
Reputation: 1676
replace() returns a copy of the string with all occurrences of substring old replaced by new
You need to assign to a variable to store the copy
str = "Python"
replaced_str= str.replace("th", "t")
print(replaced_str)
Upvotes: 1