---
title: "What is the difference between @staticmethod and @classmethod?"  
description: "What is the difference between @staticmethod and @classmethod?"  
author: "Utpal Vishwas"  
published: 2023-04-11  
updated: 2023-05-02  
canonical: https://www.mindstick.com/forum/157749/what-is-the-difference-between-staticmethod-and-classmethod  
category: "python"  
tags: ["oops", "python"]  
reading_time: 3 minutes  

---

# What is the difference between @staticmethod and @classmethod?

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between @staticmethod and @classmethod?

## Replies

### Reply by Aryan Kumar

**@staticmethod** and **@classmethod** are two different decorators used to define methods inside a class. The main difference between them is how they handle the first parameter of the method\
\
**@staticmethod** is used to define a method that does not take any special first argument. It is similar to a regular function outside of a class, but is defined inside a class. **@staticmethod** does not receive any reference to the instance of the class, nor to the class itself.\
\
**@classmethod** is used to define a method that takes a reference to the class itself as its first argument. This first argument is usually called **cls** by convention, instead of **self**. This allows the method to access the class and its attributes.\
\
class MyClass:\
@staticmethod\
def my_static_method(x, y):\
return x + y

result = MyClass.my_static_method(3, 5)\
print(result) # Output: 8\
\
`class MyClass:`\
`class_variable = 10`

`@classmethod`\
`def my_class_method(cls, x):`\
`return cls.class_variable + x`

`result = MyClass.my_class_method(5)`\
`print(result) # Output: 15`\

### Reply by Krishnapriya Rajeev

We use the **@staticmethod** and **@classmethod** decorators in Python to define methods within a class, but each of them has different purposes and uses.

The **@staticmethod** decorator is used to define a method that does not access or modify the state of an instance, and a special first argument is not passed. It is similar to a regular function that is defined outside the class, but it is within the scope of the class and can be called using the class name or an instance of the class.

```cs
class Class1:
   @staticmethod
   def static_method():
       print("This is a static method")

# Call the static method using the class name
Class1.static_method()

# Call the static method using an instance of the class
obj = Class1()
obj.static_method()

# Output = This is a static method
```

This is a static method

The **@classmethod** decorator is used to define a method that operates on the class and receives the class itself as the first argument, which is conventionally named cls. This method can access and modify the state of the class or create new instances of the class. It can also be called using the name of the class or an instance of the class.

```cs
class Class2:
   count = 0

   def __init__(self):
       Class2.count += 1

   @classmethod
   def get_count(cls):
       print("The count is:", cls.count)

# Create instances of the class
obj1 = Class2()
obj2 = Class2()

# Call the class method using the class name
Class2.get_count()

# Call the class method using an instance of the class
obj1.get_count()

# Output = The count is: 2
           The count is: 2
```


---

Original Source: https://www.mindstick.com/forum/157749/what-is-the-difference-between-staticmethod-and-classmethod

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
