Questions
15 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?
15 / 19

What is the difference between an instance method, a class method, and a static method?

Difficulty: 5/10
Methods, Classmethod, Staticmethod, Descriptors

Instance method binds self, classmethod binds cls, staticmethod binds nothing

All three are functions stored on the class and resolved through the descriptor protocol, but they bind differently. An instance method receives the instance as the first argument. A classmethod receives the class as the first argument, whether called on the class or on an instance, which makes it useful for alternative constructors and polymorphic factories. A staticmethod receives neither: it is a plain function namespaced under the class, useful for grouping utilities or when you want no implicit binding. The mechanism is that classmethod and staticmethod are descriptors with their own get implementations, not just markers.

  1. 1

    Use classmethod for alternative constructors (from_json, from_config) and for methods that must respect subclassing.

  2. 2

    Use staticmethod for pure helpers that logically belong to the class but need no class or instance state.

  3. 3

    Use instance method for anything that reads or mutates per-instance state.

  4. 4

    Trade-off: classmethods are polymorphic through cls, which staticmethods are not. If a factory needs to build subclass instances, classmethod is the right tool.

  5. 5

    Common mistake: writing a staticmethod that silently depends on class attributes. It should be a classmethod.

  6. 6

    Version note: classmethod and staticmethod have been stable since Python 2.4; calling them as plain functions (e.g., classmethod(f)) before the decorator syntax works but is legacy.

javascript

Scenario Questions

0-2 years experience

  1. 1You need a helper that validates an email and does not use self or cls. Which decorator?
  2. 2Why does a classmethod work when called on a subclass?

2-5 years experience

  1. 1You want a User.from_dict alternative constructor that works for subclasses. Which method type and why?
  2. 2A staticmethod accesses a class attribute directly by class name and breaks under subclass overrides. How do you fix it?

5-8 years experience

  1. 1You need a factory that returns different subclasses based on a config flag. How do you design it with classmethods?
  2. 2You are building a plugin registry where classes register themselves on definition. Where does the registration logic live?

8+ years experience

  1. 1Design a polymorphic deserialization layer using classmethods that remains correct with cooperative multiple inheritance.
  2. 2Compare classmethod, staticmethod, and module-level functions on discoverability, testability, and mockability in a large codebase.

Follow-up Questions

  • Why does from_json return an Admin instance when called on Admin?
  • When would a staticmethod actually be a code smell?
Share

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