I have the following piece of code:
class test:
def __init__(self):
self.variable = 'Old'
self.change(self.variable)
def change(self, var):
var = 'New'
obj = test()
print(obj.variable)
The output is Old
but I don't understand - the method change
gets a REFERENCE to the class variable variable
then why doesn't self.variable
change to New
if I assigned a new string to the pointer inside the class ?
I know the string itself is immutable but doesn't it change the value of the pointer represented by self.variable
?
Wouldn't it be the same as: *var = 'New'
in C ?