---
title: "What’s the difference between @staticmethod, @classmethod, and instance methods?"  
description: "What’s the difference between @staticmethod, @classmethod, and instance methods?"  
author: "Ravi Vishwakarma"  
published: 2025-08-28  
updated: 2025-08-29  
canonical: https://www.mindstick.com/forum/161894/what-s-the-difference-between-staticmethod-classmethod-and-instance-methods  
category: "python"  
tags: ["python", "Python 3"]  
reading_time: 3 minutes  

---

# What’s the difference between @staticmethod, @classmethod, and instance methods?

**What’s the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between** `@staticmethod`**,** `@classmethod`**, and [instance methods](https://www.mindstick.com/forum/23099/difference-between-static-methods-and-instance-methods-in-java)?**

## Replies

### Reply by Anubhav Sharma

## 1. Instance Method (default)

- Defined with `self` as the **first parameter**.
- Operates **on an [instance](https://www.mindstick.com/forum/155658/testing-connection-to-cloud-sql-instance-with-a-mysql-client-from-vm-instance) of the class**.
- Can access **instance attributes (**`self.attr`**)** and **class attributes**.
- Called **on an object**.

```python
class Example:
    def instance_method(self):
        return f"Called instance_method from {self}"

e = Example()
print(e.instance_method())   #works
# Output: Called instance_method from <__main__.Example object at 0x...>
```

Use when you need to work with **data tied to a specific object**.

## 2. Class Method

- Defined with `@classmethod` decorator.
- Takes `cls` (class itself) as the **first parameter**.
- Cannot access **instance-specific data** (`self`), but **can modify class-level data**.
- Can be called **on both the class and an instance**.

```python
class Example:
    count = 0

    @classmethod
    def increment_count(cls):
        cls.count += 1
        return cls.count

print(Example.increment_count())  # 1
print(Example.increment_count())  # 2
```

Use when you need [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) that work with **class-level state** (shared across all instances), or when you want **alternate constructors**.

## 3. Static Method

- Defined with `@staticmethod`.
- Doesn’t take `self` or `cls`.
- Behaves like a **regular function inside a class’s namespace**.
- Cannot access instance attributes or class attributes directly.

```python
class Example:
    @staticmethod
    def add(a, b):
        return a + b

print(Example.add(5, 3))   # 8
```

Use when the method **doesn’t need instance (**`self`**) or class (**`cls`**) data**, but logically belongs to the class.

## Quick Comparison

| Type | First Arg | Can Access Instance (`self`) | Can Access Class (`cls`) | Typical Use |
| --- | --- | --- | --- | --- |
| **Instance Method** | `self` | Yes | Yes | Work with object state |
| **Class Method** | `cls` | No | Yes | Work with class state, alternative constructors |
| **Static Method** | None | No | No | Utility functions that logically belong to the class |

## Real-world Analogy

Think of a **Bank Account class**:

```python
class BankAccount:
    interest_rate = 0.05  # class attribute

    def __init__(self, owner, balance=0):
        self.owner = owner      # instance attribute
        self.balance = balance

    def deposit(self, amount):       # Instance method
        self.balance += amount
        return self.balance

    @classmethod
    def set_interest_rate(cls, rate): # Class method
        cls.interest_rate = rate

    @staticmethod
    def validate_amount(amount):      # Static method
        return amount > 0

acc1 = BankAccount("Alice", 1000)
print(acc1.owner, acc1.balance)
# Instance method
acc1.deposit(500)
print(acc1.owner, acc1.balance)

# Class method
BankAccount.set_interest_rate(0.07)
print(BankAccount.interest_rate)

# Static method
print(BankAccount.validate_amount(200))
```

- `deposit` → Needs to update **that account’s balance** → instance method.
- `set_interest_rate` → Affects **all accounts** (class-level) → class method.
- `validate_amount` → Just a check, doesn’t depend on account or bank → static method.

## Output -

```plaintext
Alice 1000
Alice 1500
0.07
True
```


---

Original Source: https://www.mindstick.com/forum/161894/what-s-the-difference-between-staticmethod-classmethod-and-instance-methods

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
