+ 1
Why is a() + b() translated to b.__radd__(a())
This is from the magic methods lesson question 2. I keep thinking the add function/method is a part of a when you call it, so it should be a.__radd__(b()) right?
1 Odpowiedź
+ 8
a() + b() is translated to a.__add__(b()).
__radd__ is "reverse add". The lesson says that if __add__ hasn't been defined, it will look for __radd__ and translate a() + b() to b.__radd__(a()).