(SOLVED) Python magic "r..." methods | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9

(SOLVED) Python magic "r..." methods

What is the purpose of "r" magic methods, like __radd__? SoloLearn didn't explained that well.

8th Jul 2021, 12:09 PM
Xemonix
Xemonix - avatar
2 Answers
+ 3
when doing a+b It tries to do a.__add__(b) If it is not defined then it tries b.__radd__(a) It's called __radd__ becouse it's the object on the right side of the operand to call it
8th Jul 2021, 12:35 PM
Angelo
Angelo - avatar
+ 7
Angelo Thank you for answer! 😊
8th Jul 2021, 1:04 PM
Xemonix
Xemonix - avatar