Does an immutable object in python mean that its value cannot be changed after its conception?
If that is the case what will happen when we try to change its value.
Let me try to explain my doubt with an example.
For instance I initialized a String object S with value "Hello World".
S = 'Hello World'
Then I typed in the line,
S = 'Hello Human'
So when I ask the interpreter, it tells me the value of S is "Hello Human". Clearly now ‘S’ has a new value.
How did the value change? Did python destroy the old string object and created a new one with the new value? or did it just changed the value of the old object. Does this has anything to do with the fact that the string object is immutable? If so, then how do mutable objects behave?
Python stopped
Spointing to the the old string object and made it point to a new oneYou can’t change immutable objects, so even when you think you muight be (eg with the
+=operator) you aren’t