Questions
6 of 19
1How would you make a custom class usable in a for loop?
2How do __enter__ and __exit__ work together to implement the context manager protocol?
3How does Python implement inheritance, and what is the Method Resolution Order (MRO)?
4What are dataclasses, and how do they reduce boilerplate compared to manually writing __init__, __eq__, and __repr__?
5What is the @property decorator, and what problem does it solve compared to plain getter/setter methods?
6What is the difference between method overriding and method overloading, and why doesn't Python natively support overloading?
7What problem does the diamond inheritance pattern cause, and how does Python's MRO resolve it?
8What is the difference between a class and an instance in Python?
9How does Python implement encapsulation given that it has no true 'private' access modifiers?
10What is the purpose of self in instance methods, and why must it be explicitly declared in Python?
11What is the difference between __str__ and __repr__, and what convention should __repr__ follow?
12What is a metaclass, and what is type's relationship to every class in Python?
13What is the purpose of __eq__ and __hash__, and why must they be implemented consistently?
14What is a descriptor, and how do @property and ORMs like Django's models rely on the descriptor protocol?
15What is the difference between an instance method, a class method, and a static method?
16What is composition, and why is 'favor composition over inheritance' often recommended?
17What are dunder (magic) methods, and how do they enable operator overloading?
18When would you use a metaclass instead of a class decorator or __init_subclass__?
19How do abstract base classes (abc.ABC) enforce interface contracts in Python?
06 / 19

What is the difference between method overriding and method overloading, and why doesn't Python natively support overloading?

Difficulty: 5/10
Overriding, Overloading, Singledispatch

Overriding replaces a parent method; overloading by arity is unnecessary in a dynamically typed language

Overriding is when a subclass defines a method with the same name as an ancestor; the subclass version replaces the ancestor for that lookup path. Overloading traditionally means multiple methods with the same name but different signatures, resolved by argument count or types at compile time. Python does not resolve by signature because names are bound at runtime and functions accept any arguments. Instead, one function handles multiple forms using default arguments, *args/**kwargs, type checks, or singledispatch. Defining the same method twice in a class simply overwrites the first definition, which is a frequent surprise for engineers coming from Java or C++.

  1. 1

    Use default arguments and **kwargs for simple arity variation.

  2. 2

    Use functools.singledispatch or singledispatchmethod for type-based dispatch, which is the closest idiomatic Python gets to overloading.

  3. 3

    Use typing.overload purely for static type checkers; it has no runtime effect.

  4. 4

    Trade-off: runtime dispatch is flexible but hides branching. singledispatch makes dispatch explicit and extensible.

  5. 5

    Common mistake: defining two methods with the same name in one class and expecting both to be callable. Only the last one exists.

  6. 6

    Version note: singledispatch is in functools since 3.4; singledispatchmethod since 3.8. typing.overload is a type-checker construct, not runtime behavior.

javascript

Scenario Questions

0-2 years experience

  1. 1You define two methods named area with different parameters. Why does only one work?
  2. 2What is the simplest way to support an optional argument in a method?

2-5 years experience

  1. 1You need the same function name to handle int, str, and list differently. What is the idiomatic tool?
  2. 2A teammate uses typing.overload and expects it to dispatch at runtime. How do you correct them?

5-8 years experience

  1. 1You need a pluggable dispatch mechanism that third parties can extend without editing your module. How do you build it?
  2. 2You are porting Java-style overloaded APIs to Python. How do you preserve type-safety and readability?

8+ years experience

  1. 1Design a dispatch layer that handles both type-based and arity-based selection with good performance and introspectable error messages.
  2. 2Explain the trade-offs between singledispatch, explicit isinstance branching, and a registry pattern for extensible dispatch.

Follow-up Questions

  • Why does defining the same method twice in a class not create an overload?
  • When is singledispatch preferable to isinstance checks inside one function?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.