How do reflected numeric dunders such as __radd__ get chosen?
PICTURE THIS: HOW TO EXPLAIN IT
Simple meaning
For a + b, Python tries a.__add__(b)
WHY — Dunder Methods instead of guessing?
Why interviewers care about Dunder Methods:
question about Dunder Methods.
trade-offs, and what you would actually do on a Python project - not buzzwords.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens step by step?
Before you speak the answer, walk the interviewer through these steps:
- 1For a + b,
Python tries a.__add__(b)
- 2if that returns NotImplemented,
it tries b.__radd__(a).
- 3Subclass instances may skip
the left op so the subclass can coerce types.
- 4Returning NotImplemented rather than
raising TypeError is what makes mixed-type arithmetic work.
- 5Common mistake
What juniors usually get wrong.
- 6Close
When you pick this over the alternative.
EXAMPLE — See it in action
Here's a short line you can speak, broken into clear beats:
Note: Adapt this scaffold to your own project — keep it under 60–90 seconds.
Key takeaway
For a + b, Python tries a.__add__(b) if that returns NotImplemented, it tries b.__radd__(a).