New course! Every coder should learn Generative AI!
Try a free lesson+ 2
Why does returning the "NotImplemented" object raise a "TypeError" only when the objects are separated by the plus sign?
I had thought that the '+' sign behaves exactly like the '__add__' magic method; it seems not (the question is in the code): https://code.sololearn.com/ct7Sp8mRc0x4/?ref=app
3 Answers
0
✩✮★✮✩ I had thought that returning "NotImplemented" will always raise the error. In which all cases does this raise the error, apart from __add__, __sub__, __radd__, __rsub__ and all the magic methods involving arithmetic operations and comparisons? I mean, does returning "NotImplemented" from a method raise a "TypeError" only if the method is a magic method relating to the arithmetic operations? I guess that this is a special case.
0
✩✮★✮✩ But this doesn't happen when I return None, right?
0
✩✮★✮✩ I see, thank you.