I'm very new to python and currently practicing OOP. One of the problems I'm facing is how to change an instance variable in python using a method. My code:
class Monster:
def __init__ (self, name, health):
self.name = name
self.health = health
@classmethod
def change_name (self, given_name):
self.name = given_name
mon = Monster("Drake", 100)
print(mon.name)
mon.change_name("Derrick")
print(mon.name)
Output:
#Expected:
Drake
Derrick
#Actual:
Drake
Drake
Can someone tell me what the problem is and how I can solve it?