Sunday, 7 October 2018

Why doesn't calling a Python string method do anything unless you assign its output?

I try to do a simple string replacement, but I don't know why it doesn't seem to work:

X = "hello world"
X.replace("hello", "goodbye")

I want to change the word hello to goodbye, thus it should change the string "hello world" to "goodbye world". But X just remains "hello world". Why is my code not working?



from Why doesn't calling a Python string method do anything unless you assign its output?

No comments:

Post a Comment