ReviseAlgo Logo

Object-Oriented Programming

Methods

Instance, class, and static methods with real-world patterns

Interview: Very common — interviewers test your understanding of when to use each method type and how self/cls work

Last Updated: June 12, 2026 7 min read

Methods are functions defined inside a class that describe the behavior of objects. Python has three types of methods, each with different access to the class and instance: instance methods, class methods, and static methods. Choosing the right type is an important design decision.

Instance Methods

The most common type. They receive self as the first parameter and can access/modify instance attributes and call other methods. Use them when you need to work with object-specific data.

Class Methods

Decorated with @classmethod, they receive cls (the class itself) as the first parameter. Use them for factory methods, alternative constructors, and operations that affect the class rather than individual instances.

Static Methods

Decorated with @staticmethod, they receive neither self nor cls. They're utility functions that logically belong to the class but don't need class or instance data. Use them for helper functions related to the class's purpose.

Interview Tip

Be ready to explain why you'd use a @classmethod over a @staticmethod for factory methods. Answer: @classmethod receives cls, so it can return instances of subclasses correctly (polymorphic construction).

Use Cases

Instance methods for object behavior (display, calculate, validate)

Class methods as alternative constructors (from_string, from_dict, from_json)

Class methods for class-level operations (count instances, find by criteria)

Static methods for utility functions (validation, formatting, conversion)

Combining all three types for clean, well-organized class design

Common Mistakes

Using @staticmethod when @classmethod is needed (can't access class for polymorphic construction)

Forgetting @classmethod or @staticmethod decorator — method becomes instance method

Calling instance method on class without passing instance (MyClass.method() vs obj.method())

Using class methods to modify instance state (they only have cls, not self)

Not understanding that bound methods (obj.method) are different from unbound methods (Class.method)