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 Odpowiedź
+ 2
First the return function can only return 1 value and you have to write return without test ().
Here is an example:
https://code.sololearn.com/cnYp6Kv1TujA/?ref=app