Skip to content
Preptima

OOP in Python interview questions

Dunder methods, MRO and multiple inheritance, descriptors, dataclasses, and properties.

3 questions in Python.

medium1

mediumConceptCoding

If you were writing a small value type in Python, which dunder methods would you implement, what would you let a dataclass generate, and how does super() decide what to call?

Implement the dunders that opt your type into a protocol, treating repr, eq and hash as one decision, and let a dataclass generate the boilerplate when the fields are the identity. super() follows the C3 linearisation of type(self), so it calls the next class in the MRO rather than your own base.

4 minmid, senior

hard2

hardConcept

When would you reach for an abstract base class rather than a Protocol, and what does isinstance check in each case?

Use a Python ABC when you need nominal inheritance and runtime instantiation checks; use a Protocol when a type checker should accept any object with the required methods, even without inheritance. Use this abstract base classes answer to show the decision, trade-off, and evidence rather than a memorised definition. It also connects protocols to the point an interviewer is testing.

5 minmid, senior, staff
hardConceptCoding

What is a descriptor, and how does @property use one?

A Python descriptor implements __get__, and optionally __set__ or __delete__, to control attribute access; @property is a data descriptor that wins over the instance dictionary.

5 minmid, senior, staff