+ 1
__add__ and __radd__
can someone explain me the differences between __add__ and __radd__ with the help of a simple program.
6 ответов
+ 1
Check the following code example,
https://code.sololearn.com/cK03N0e1YE9U/?ref=app
+ 1
__add__ stand for "addition"
__radd__ stand for "right addition"
default addition of a+b is done by calling a.__add__(b) so technically __add__(a,b)...
if class of a doesn't implement the __add__ method, then if class of b has __radd__ method, a+b us rather done by calling b.__radd__(a) so technically __radd__(b,a)...
0
Runtime Terror can you explain using a program .?plz.
I did not get what you said😅
0
visph can we use __radd__ method for the objects of same classes ?
If yes then how ?
0
kushal no, for same class addition, the __add__ method only is called... even if you implement only __radd__ (and not __add__), you'll get an argument error ^^