+ 1

Can somebody explain for me more about r magic methods?(e.g __radd__ like in __add__)

In the Python course these magic methods aren't explained well, this made a big(? ) in my mind.

13th Aug 2019, 5:54 PM
Saeed Alqassabi
Saeed Alqassabi - avatar
6 Respostas
+ 2
Such a method is called when an object is passed as right operand.
13th Aug 2019, 6:12 PM
Ilya Vouk
Ilya Vouk - avatar
+ 2
Yes, it is. If __add__ of the left operand is not found then __radd__ of the right one is used instead.
14th Aug 2019, 5:23 AM
Ilya Vouk
Ilya Vouk - avatar
+ 2
Thank you so much 🙂 Ilya Vouk.
14th Aug 2019, 11:27 AM
Saeed Alqassabi
Saeed Alqassabi - avatar
+ 1
Do you mean r is for right?
14th Aug 2019, 2:55 AM
Saeed Alqassabi
Saeed Alqassabi - avatar
0
You're welcome👌
14th Aug 2019, 6:37 PM
Ilya Vouk
Ilya Vouk - avatar
0
These answer's make no sense to me. Can anyone give an example between a normal __add__ and __radd__?
8th Dec 2021, 3:56 AM
Allan Chuang