0
What is the use of magic method __add__?? In below code why result not returning addition of first and second???
class test: def __init__(self,x,y): self.x=x self.y=y def __add__(self,other): return test(self.x*other.x, self.y*other.y) first=test(4,7) second=test(5,6) result=first+second print(result.y)
1 Resposta
+ 7
if you use __add__ the method must return sum like
def __add__(self,other):
return self.x+other.x and not coma sepereted like you did