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)

21st Feb 2018, 5:48 PM
Pankaj Kumar
Pankaj Kumar - avatar
1 Antwort
+ 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
23rd Feb 2018, 1:13 PM
Ninj4