What happens to a immutable object in python when its value is changed?
immutability, object, python
Solution
Python stopped `S` pointing to the the old string object and made it point to a new one
>>> S="Hello World"
>>> id(S)
32386960
>>> S="Hello Human"
>>> id(S)
32387008
>>>
You can't change immutable objects, so even when you think you muight be (eg with the `+=` operator) you aren't
>>> S="Hello"
>>> id(S)
32386912
>>> S+=" World"
>>> id(S)
32386960
>>>
Problem
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?