String function: replace

string is immutable(i.e. string can not be changed) but here replace function is changing the string how?

string is immutable means we can not change its content like by specifying the particular value at particular index, but if
you know we can assign new values to the string.
for ex.
a = “Hello”
print(a)
a = “World”
print(a)

Output:
Hello
World

so we can assign the new values to the variable, similarily in the case of replace function take it like it creates the new object and instead
of that portion we word that we want to replace, place the replaced word and assign it to the variable.
So here replaced string is reassigned to the variable and it is possible with python strings.
I hope you understand this, in case of any doubt/confusion pls msg me back. I will surely help you out.
Thanks, and in case you understand this pls mark it as resolved and also provide ratings/feedback so that we can improve our services.
Happy Coding !!
Thanks :slight_smile:

@Tanu_jain Do you still have any issue with the doubt ?