Here is my code `
class Cats:
def __init__(self,name):
self.name=name
#print(self.name,name,"hello")
def change_name(self,new_name):
self.name=new_name
return 0
#print(new_name)
cat1=Cats("lion")
print(cat1)
print(cat1.name)
cat2=cat1.change_name("tiger")
print(cat1.name)
print(cat1)
print(cat2)
** Here is the output with my comments/opinion on the side (pls correct me if i am wrong):
**
<__main__.Cats object at 0x7f84272d7640>
error because I tried to print the object cat1
lion
seems fine coz i printed the attribute of the object and since the name given while initialising was lion, it printed lion
tiger
THIS IS WHAT I DON'T UNDERSTAND. why is this output tiger and not lion. what exactly caused this change? Bcoz when I do <<cat2=cat1.change_name("tiger") , it should just assign the value 0 to cat2 but why did it change the value in cat1 ?
<__main__.Cats object at 0x7f84272d7640>
error bcoz i tried to print a class
0
seems fine coz chane_name function returns 0 which is assigned to cat2
I was expecting the value of cat1.name to remain the same (it should have remained lion and not changed to tiger)