def __radd__(selfother)print('radd'self valotherreturn other self val from commuter import commuter commuter ( commuter ( __add__instance noninstance add __radd__noninstance instance radd __add__instance instancetriggers __radd__ add radd notice how the order is reversed in __radd__self is really on the right of the +and other is on the left also note that and are instances of the same class herewhen instances of different classes appear mixed in an expressionpython prefers the class of the one on the left when we add the two instances togetherpython runs __add__which in turn triggers __radd__ by simplifying the left operand reusing __add__ in __radd__ for truly commutative operations that do not require special-casing by positionit is also sometimes sufficient to reuse __add__ for __radd__either by calling __add__ directlyby swapping order and re-adding to trigger __add__ indirectlyor by simply assigning __radd__ to be an alias for __add__ at the top level of the class statement ( in the class' scopethe following alternatives implement all three of these schemesand return the same results as the original--though the last saves an extra call or dispatch and hence may be quicker (in all__radd__ is run when self is on the right side of +)class commuter def __init__(selfval)self val val def __add__(selfother)print('add'self valotherreturn self val other def __radd__(selfother)return self __add__(otherclass commuter def __init__(selfval)self val val def __add__(selfother)print('add'self valotherreturn self val other def __radd__(selfother) operator overloading call __add__ explicitly