0

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

1 Answer 1

1

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)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.