Last Updated on November 3, 2025 by Rajeev Bagra
When learning object-oriented programming (OOP) in Python, you’ll encounter three types of methods: instance methods, class methods, and static methods.
At first glance, they look quite similar — all are defined inside a class. But each serves a very different purpose depending on what kind of data or behavior it’s meant to handle.
Let’s break this down using a simple, real-world analogy: a company and its employees.
💼 Meet “Techify Solutions Pvt. Ltd.”
Imagine a company called Techify Solutions.
This company has:
- Many employees (each represented by an instance of a class).
- Some company-wide policies (that apply to everyone — defined at the class level).
- A few general utilities (like a calculator — unrelated to any specific employee or policy).
Let’s see how these map to Python’s method types.
🔹 1. Instance Methods — Actions of an Employee
An instance method works with the data that belongs to a particular object.
In our analogy, this is like an individual employee doing something — for example, getting a raise.
class Employee:
def __init__(self, name, salary):
self.name = name
self.salary = salary
def give_raise(self, percent): # instance method
self.salary += self.salary * percent
print(f"{self.name} got a raise! New salary: {self.salary}")
đź’¬ Analogy:
Rajeev, one of the employees, gets a personal raise.
This change affects only his salary, not anyone else’s.
đź§ Key idea:
- Works on instance-level data (
self) - Accesses and modifies object attributes
Usage:
rajeeve = Employee("Rajeev", 50000)
rajeeve.give_raise(0.10) # Rajeev got a raise! New salary: 55000
🔹 2. Class Methods — Company-Wide Policies
A class method affects the class itself, not any specific employee.
In a business, this is like a new company-wide policy that applies to everyone.
class Employee:
raise_percent = 0.05 # default raise policy
@classmethod
def update_raise_policy(cls, new_rate): # class method
cls.raise_percent = new_rate
print(f"Company policy updated: {cls.raise_percent*100}% raise for all employees!")
đź’¬ Analogy:
The HR department decides that everyone will now receive a 10% raise instead of 5%.
This affects all employees equally.
đź§ Key idea:
- Works on class-level data (
cls) - Commonly used for factory methods or policy updates
Usage:
Employee.update_raise_policy(0.10)
# Company policy updated: 10.0% raise for all employees!
🔹 3. Static Methods — General Utilities
A static method doesn’t depend on any class or instance data.
It’s just a helper function that happens to live inside the class for organizational purposes.
class Employee:
@staticmethod
def calculate_tax(amount): # static method
return amount * 0.2
đź’¬ Analogy:
Think of it as a tax calculator tool that anyone can use.
It doesn’t care about the company or the employee’s details — it just calculates tax.
đź§ Key idea:
- Takes no
selforcls - Belongs logically to the class but doesn’t interact with it
Usage:
tax = Employee.calculate_tax(60000)
print(f"Tax on salary: {tax}") # Tax on salary: 12000.0
🔹 Bringing It All Together
Here’s a complete class demonstrating all three types of methods side by side:
class Employee:
raise_percent = 0.05 # class variable
def __init__(self, name, salary):
self.name = name
self.salary = salary
# Instance method
def give_raise(self):
self.salary += self.salary * Employee.raise_percent
print(f"{self.name}'s new salary: {self.salary}")
# Class method
@classmethod
def update_raise_policy(cls, new_rate):
cls.raise_percent = new_rate
print(f"Company-wide raise policy updated to {cls.raise_percent*100}%")
# Static method
@staticmethod
def calculate_tax(amount):
return amount * 0.2
Usage:
# Updating company policy
Employee.update_raise_policy(0.10)
# Creating employees
rajeeve = Employee("Rajeev", 50000)
amrita = Employee("Amrita", 60000)
# Applying raise (instance method)
rajeeve.give_raise()
amrita.give_raise()
# Using static method
print("Tax on 50000:", Employee.calculate_tax(50000))
đź§ Summary Table
| Method Type | Works On | Needs | Example Use | Real-World Analogy |
|---|---|---|---|---|
| Instance Method | Individual object | self | Give raise to one employee | Rajeev gets a personal raise |
| Class Method | The class itself | cls | Update raise policy for all | HR changes company policy |
| Static Method | Neither | None | Calculate tax | Company’s general calculator tool |
đź’ˇ Final Takeaway
- Instance Method → Talks to the object (needs
self). - Class Method → Talks to the class itself (needs
cls). - Static Method → Talks to no one — just performs a general task.
When you understand this distinction, you can write cleaner, more maintainable Python code that reflects real-world logic beautifully.
Discover more from Aiannum.com
Subscribe to get the latest posts sent to your email.




Leave a Reply