The most straightforward way to think about it is to think in terms of what type of object the method needs in order to do its work. If your method needs access to an instance, make it a regular method. If it needs access to the class, make it a classmethod. If it doesn't need access to the class or the instance, make it a function. There is rarely a need to make something a staticmethod, but if you find you want a function to be "grouped" with a class (e.g., so it can be overridden) even though it doesn't need access to the class, I guess you could make it a staticmethod.

I would add that putting functions at the module level doesn't "pollute" the namespace. If the functions are meant to be used, they're not polluting the namespace, they're using it just as it should be used. Functions are legitimate objects in a module, just like classes or anything else. There's no reason to hide a function in a class if it doesn't have any reason to be there.

Answer from BrenBarn on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › class-method-vs-static-method-python
Class method vs Static method in Python - GeeksforGeeks
July 26, 2024 - In general, static methods know nothing about the class state. They are utility-type methods that take some parameters and work upon those parameters. On the other hand class methods must have class as a parameter.
🌐
DEV Community
dev.to › adamlombard › python-class-vs-instance-vs-static-methods-2cd0
Python: class vs. instance vs. static methods - DEV Community
March 20, 2024 - In Python, a method provides functionality to a Class. ... Static Methods : Provide functionality that can be accessed from a class or from one instance of a class
Discussions

CLASS & STATIC METHODS
Classes for Beginners A lot of beginners struggle to get their heads around classes, but they are pretty much fundamental to object orientated programming. I usually describe them as the programming equal of moulds used in factories as a template for making lots of things that are identical. Imagine pouring molten iron into a mould to make a simple iron pot. You might produce a set of instructions to be sold with the pots that tell the owner how to cook using the pot, how to care for it, etc. The same instructions apply to every pot BUT what owners actually do is entirely up to them. Some might make soup, another person a stew, etc. In Python, a class defines the basics of a possible object and some methods that come with it. (Methods are like functions, but apply to things made using the class.) When we want create a Python object using a class, we call it 'creating an instance of a class'. If you have a class called Room, you would create instances like this: lounge = Room() kitchen = Room() hall = Room() As you typically want to store the main dimensions (height, length, width) of a room, whatever it is used for, it makes sense to define that when the instance is created. You would therefore have a method called __init__ that accepts height, length, width and when you create an instance of Room you would provide that information: lounge = Room(1300, 4000, 2000) The __init__ method is called automatically when you create an instance. It is short for initialise (intialize). You can reference the information using lounge.height and so on. These are attributes of the lounge instance. I provided the measurements in mm but you could include a method (function inside a class) that converts between mm and ft. Thus, I could say something like lounge.height_in_ft(). Methods in classes are usually defined with a first parameter of self: def __init__(self, height, length, width): # code for __init__ def height_in_ft(self): # code to return height The self is a shorthand way of referring to an instance. When you use lounge.height_in_ft() the method knows that any reference to self means the lounge instance, so self.height means lounge.height but you don't have to write the code for each individual instance. Thus kitchen.height_in_ft() and bathroom.height_in_ft() use the same method, but you don't have to pass the height of the instance as the method can reference it using self.height EXAMPLE Room class The code shown as the end of this post will generate the following output: Lounge 1300 4000 4000 Snug 1300 2500 2500 Lounge length in feet: 4.26509187 Snug wall area: 11700000 in sq.mm., 125.94 in sq.ft. Note that a method definition that is preceded by the command, @staticmethod (a decorator) is really just a function that does not include the self reference to the calling instance. It is included in a class definition for convenience and can be called by reference to the class or the instance: Room.mm_to_ft(mm) lounge.mm_to_ft(mm) Here's the code for the full programme: class Room(): def __init__(self, name, height, length, width): self.name = name self.height = height self.length = length self.width = width @staticmethod def mm_to_ft(mm): return mm * 0.0032808399 @staticmethod def sqmm_to_sqft(sqmm): return sqmm * 1.07639e-5 def height_in_ft(self): return Room.mm_to_ft(self.height) def width_in_ft(self): return Room.mm_to_ft(self.width) def length_in_ft(self): return Room.mm_to_ft(self.length) def wall_area(self): return self.length * 2 * self.height + self.width * 2 * self.height lounge = Room('Lounge', 1300, 4000, 2000) snug = Room('Snug', 1300, 2500, 2000) print(lounge.name, lounge.height, lounge.length, lounge.length) print(snug.name, snug.height, snug.length, snug.length) print(lounge.name, 'length in feet:', lounge.height_in_ft()) print(f'{snug.name} wall area: {snug.wall_area()} in sq.mm., ' + \ f'{snug.sqmm_to_sqft(snug.wall_area()):.2f} in sq.ft.') Another useful decorator is @property, which allows you to refer to a method as if it is an attribute. Not used in the example, but if I put that before the height_in_ft methods you could say, for example, lounge.height_in_ft instead of lounge.height_in_ft(). One can write classes that are based on other classes. These child classes inherit all of the characteristics of the parent (or super) class but any attribute or method can be overridden to use alternatives that apply only to the child (and its children). Such child classes might have additional methods, alternative __init__ methods, different default output when referenced in a print statement, and so on. The example code code does not demonstrate this feature. More on reddit.com
🌐 r/learnpython
12
2
December 30, 2021
python - Module function vs staticmethod vs classmethod vs no decorators: Which idiom is more pythonic? - Stack Overflow
A static method in Java does not translate to a Python classmethod. Oh sure, it results in more or less the same effect, but the goal of a classmethod is actually to do something that's usually not even possible in Java (like inheriting a non-default constructor). More on stackoverflow.com
🌐 stackoverflow.com
oop - What is the difference between @staticmethod and @classmethod in Python? - Stack Overflow
What is the difference between a method decorated with @staticmethod and one decorated with @classmethod? ... static methods are sometimes better off as module level functions in python for the sake of cleanliness. With a module function it is easier to import just the function you need and ... More on stackoverflow.com
🌐 stackoverflow.com
@staticmethod vs @classmethod vs functions outside of class in Python - Software Engineering Stack Exchange
I have some static functions in a Python class. The advantage to using the @staticmethod decorator is that it informs the reader that the method doesn't require any information from the class or More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
🌐
Real Python
realpython.com › instance-class-and-static-methods-demystified
Python's Instance, Class, and Static Methods Demystified – Real Python
March 17, 2025 - These are the most common methods in Python classes. Class methods use a cls parameter pointing to the class itself. They can modify class-level state through cls, but they can’t modify individual instance state.
🌐
Wiingy
wiingy.com › home › learn › python › class method vs static method in python
Class Method vs Static Method in Python (With Examples)
January 30, 2025 - In Python, the main distinction ... is that the former is used to carry out operations related to the class as a whole, whereas the latter is used to carry out operations unrelated to any particular instance of the class...
🌐
Reddit
reddit.com › r/learnpython › class & static methods
r/learnpython on Reddit: CLASS & STATIC METHODS
December 30, 2021 -

Hello everyone,

I was studying OOP and the concept of instances, class methods and static methods still confuses me.

I have watched tons of YouTube already but I can't find a person who explains it as dumb as possible because that is how I understand things.

Please if there is anyone who can recommend to me a video or explain it to me in the simplest way possible with examples, I will be glad :)

Note: I want the simplest form of explanation about the matter.

Top answer
1 of 5
3
Classes for Beginners A lot of beginners struggle to get their heads around classes, but they are pretty much fundamental to object orientated programming. I usually describe them as the programming equal of moulds used in factories as a template for making lots of things that are identical. Imagine pouring molten iron into a mould to make a simple iron pot. You might produce a set of instructions to be sold with the pots that tell the owner how to cook using the pot, how to care for it, etc. The same instructions apply to every pot BUT what owners actually do is entirely up to them. Some might make soup, another person a stew, etc. In Python, a class defines the basics of a possible object and some methods that come with it. (Methods are like functions, but apply to things made using the class.) When we want create a Python object using a class, we call it 'creating an instance of a class'. If you have a class called Room, you would create instances like this: lounge = Room() kitchen = Room() hall = Room() As you typically want to store the main dimensions (height, length, width) of a room, whatever it is used for, it makes sense to define that when the instance is created. You would therefore have a method called __init__ that accepts height, length, width and when you create an instance of Room you would provide that information: lounge = Room(1300, 4000, 2000) The __init__ method is called automatically when you create an instance. It is short for initialise (intialize). You can reference the information using lounge.height and so on. These are attributes of the lounge instance. I provided the measurements in mm but you could include a method (function inside a class) that converts between mm and ft. Thus, I could say something like lounge.height_in_ft(). Methods in classes are usually defined with a first parameter of self: def __init__(self, height, length, width): # code for __init__ def height_in_ft(self): # code to return height The self is a shorthand way of referring to an instance. When you use lounge.height_in_ft() the method knows that any reference to self means the lounge instance, so self.height means lounge.height but you don't have to write the code for each individual instance. Thus kitchen.height_in_ft() and bathroom.height_in_ft() use the same method, but you don't have to pass the height of the instance as the method can reference it using self.height EXAMPLE Room class The code shown as the end of this post will generate the following output: Lounge 1300 4000 4000 Snug 1300 2500 2500 Lounge length in feet: 4.26509187 Snug wall area: 11700000 in sq.mm., 125.94 in sq.ft. Note that a method definition that is preceded by the command, @staticmethod (a decorator) is really just a function that does not include the self reference to the calling instance. It is included in a class definition for convenience and can be called by reference to the class or the instance: Room.mm_to_ft(mm) lounge.mm_to_ft(mm) Here's the code for the full programme: class Room(): def __init__(self, name, height, length, width): self.name = name self.height = height self.length = length self.width = width @staticmethod def mm_to_ft(mm): return mm * 0.0032808399 @staticmethod def sqmm_to_sqft(sqmm): return sqmm * 1.07639e-5 def height_in_ft(self): return Room.mm_to_ft(self.height) def width_in_ft(self): return Room.mm_to_ft(self.width) def length_in_ft(self): return Room.mm_to_ft(self.length) def wall_area(self): return self.length * 2 * self.height + self.width * 2 * self.height lounge = Room('Lounge', 1300, 4000, 2000) snug = Room('Snug', 1300, 2500, 2000) print(lounge.name, lounge.height, lounge.length, lounge.length) print(snug.name, snug.height, snug.length, snug.length) print(lounge.name, 'length in feet:', lounge.height_in_ft()) print(f'{snug.name} wall area: {snug.wall_area()} in sq.mm., ' + \ f'{snug.sqmm_to_sqft(snug.wall_area()):.2f} in sq.ft.') Another useful decorator is @property, which allows you to refer to a method as if it is an attribute. Not used in the example, but if I put that before the height_in_ft methods you could say, for example, lounge.height_in_ft instead of lounge.height_in_ft(). One can write classes that are based on other classes. These child classes inherit all of the characteristics of the parent (or super) class but any attribute or method can be overridden to use alternatives that apply only to the child (and its children). Such child classes might have additional methods, alternative __init__ methods, different default output when referenced in a print statement, and so on. The example code code does not demonstrate this feature.
2 of 5
1
THIS VIDEO SEEMS TO BE DEEP IN TO : https://youtu.be/_EljKJHSGis?si=OO2QBUKRe2FNERfM VIST IS
Find elsewhere
🌐
Medium
medium.com › @avijit.bhattacharjee1996 › instance-methods-static-methods-and-class-methods-in-python-a-comprehensive-guide-9163de3f4a47
Instance Methods, Static Methods, and Class Methods in Python: A Comprehensive Guide | by Avijit Bhattacharjee | Medium
September 22, 2023 - Instance methods are used to ... within a class and are the default choice for defining methods. Static methods are defined using the @staticmethod decorator....
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › python classmethod vs staticmethod
Python Classmethod vs Staticmethod | Learn the Top Differences
April 13, 2023 - Class methods are alternative to constructors and Static methods do not operate on instance or class in Python.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Top answer
1 of 16
4020

Maybe a bit of example code will help: Notice the difference in the call signatures of foo, class_foo and static_foo:

class A(object):
    def foo(self, x):
        print(f"executing foo({self}, {x})")

    @classmethod
    def class_foo(cls, x):
        print(f"executing class_foo({cls}, {x})")

    @staticmethod
    def static_foo(x):
        print(f"executing static_foo({x})")

a = A()

Below is the usual way an object instance calls a method. The object instance, a, is implicitly passed as the first argument.

a.foo(1)
# executing foo(<__main__.A object at 0xb7dbef0c>, 1)

With classmethods, the class of the object instance is implicitly passed as the first argument instead of self.

a.class_foo(1)
# executing class_foo(<class '__main__.A'>, 1)

You can also call class_foo using the class. In fact, if you define something to be a classmethod, it is probably because you intend to call it from the class rather than from a class instance. A.foo(1) would have raised a TypeError, but A.class_foo(1) works just fine:

A.class_foo(1)
# executing class_foo(<class '__main__.A'>, 1)

One use people have found for class methods is to create inheritable alternative constructors.


With staticmethods, neither self (the object instance) nor cls (the class) is implicitly passed as the first argument. They behave like plain functions except that you can call them from an instance or the class:

a.static_foo(1)
# executing static_foo(1)

A.static_foo('hi')
# executing static_foo(hi)

Staticmethods are used to group functions which have some logical connection with a class to the class.


foo is just a function, but when you call a.foo you don't just get the function, you get a "partially applied" version of the function with the object instance a bound as the first argument to the function. foo expects 2 arguments, while a.foo only expects 1 argument.

a is bound to foo. That is what is meant by the term "bound" below:

print(a.foo)
# <bound method A.foo of <__main__.A object at 0xb7d52f0c>>

With a.class_foo, a is not bound to class_foo, rather the class A is bound to class_foo.

print(a.class_foo)
# <bound method type.class_foo of <class '__main__.A'>>

Here, with a staticmethod, even though it is a method, a.static_foo just returns a good 'ole function with no arguments bound. static_foo expects 1 argument, and a.static_foo expects 1 argument too.

print(a.static_foo)
# <function static_foo at 0xb7d479cc>

And of course the same thing happens when you call static_foo with the class A instead.

print(A.static_foo)
# <function static_foo at 0xb7d479cc>
2 of 16
990

A staticmethod is a method that knows nothing about the class or instance it was called on. It just gets the arguments that were passed, no implicit first argument.

A classmethod, on the other hand, is a method that gets passed the class it was called on, or the class of the instance it was called on, as first argument. This is useful when you want the method to be a factory for the class: since it gets the actual class it was called on as first argument, you can always instantiate the right class, even when subclasses are involved. Observe for instance how dict.fromkeys(), a classmethod, returns an instance of the subclass when called on a subclass:

>>> class DictSubclass(dict):
...     def __repr__(self):
...         return "DictSubclass"
... 
>>> dict.fromkeys("abc")
{'a': None, 'c': None, 'b': None}
>>> DictSubclass.fromkeys("abc")
DictSubclass
>>> 
Top answer
1 of 2
3

If your method calls a static method on the class, then it does require information on the class. You have a class method, not a static method. By declaring it @classmethod (and adding the cls parameter), you not only properly inform the reader, you allow polymorphism. An inheritor can reimplement the called static method and change behavior.

2 of 2
2

Python's static methods are intended for methods that are part of a class, and can be called as either a class method or an instance method: both Class.the_method() and self.the_method() would work. When the static method is called, it is not given an implicit first argument:

class Example:
  def instance_method_example(self, arguments):
    ...

  @classmethod
  def class_method_example(cls, arguments):
    ...

  @staticmethod
  def static_method_example(arguments):
    ...

If you merely want to create a helper function that is used within your class, do not use @staticmethod. Define a free function outside of the class. For example:

class Example:
  def some_method(self, argument):
    return _helper(argument, self.x)

def _helper(a, b):
  ...

The background of static methods in Python is the following: when you access an attribute of an object x.attribute or getattr(x, 'attribute'), then this name is looked up in the instance dict or the class dict. If an object is found in the class dict, it is checked whether that object is a “descriptor”: an object that describes how this attribute behaves, not an object that would be directly returned. Descriptors have dunder-methods like __get__, __set__, and __del__ that are invoked depending on whether the descriptor is accessed, assigned to, or deleted with the del operator.

Functions – the things you declare with def – are descriptors. By default, the __get__ descriptor binds the function to the instance argument (typically called self) and returns the bound function, so that it can be invoked as a method. But the various decorators change this behaviour:

  • a @classmethod def binds to the class object, not the instance
  • a @staticmethod def does not bind to any object and just returns the underlying function directly
  • a @property invokes the underlying function to retrieve a value

These differences are (partially) visible when looking at the repr() of the bound methods. With the first Example class:

  • instance_method_example
    • with class: Example.instance_method_example
      is <function Example.instance_method_example at 0x7f1dfdd6fd30>,
      the unbound function
    • with instance: <function Example.instance_method_example at 0x7f1dfdd6fd30>
      is <bound method Example.instance_method_example of <__main__.Example object at 0x7f1dfdddcb80>>,
      a method bound to the instance
  • class_method_example
    • with class: Example.class_method_example
      is <bound method Example.class_method_example of <class '__main__.Example'>>,
      a method bound to the class
    • with instance: Example().class_method_example
      is <bound method Example.class_method_example of <class '__main__.Example'>>,
      also a method bound to the class
  • static_method_example
    • with class: Example.static_method_example
      is <function Example.static_method_example at 0x7f1dfdd6fe50>,
      the unbound function
    • with instance: Example().static_method_example
      is <function Example.static_method_example at 0x7f1dfdd6fe50>,
      also the unbound function

As a table:

invoked on… no decorator @classmethod @staticmethod
… instance bound to instance bound to class unbound
… class unbound bound to class unbound
🌐
W3Schools
w3schools.com › python › python_classes.asp
Python Classes
Almost everything in Python is an object, with its properties and methods. A Class is like an object constructor, or a "blueprint" for creating objects.
🌐
Board Infinity
boardinfinity.com › blog › class-and-static-method-in-python-differences
Class and Static Method in Python: Differences | Board Infinity
January 3, 2025 - The class method can be used to manipulate the class, and its data or to create objects of the class in a different manner, while the static method in Python should be used when we have a function that does not have to know about the class or object.
🌐
Plain English
python.plainenglish.io › class-method-vs-static-method-in-python-f958d1f691c
Class Method vs Static Method in Python | by Priyanka Jain | Python in Plain English
August 30, 2024 - In Python, there are two types of methods: @classmethod and @staticmethod. Both of these methods are associated with a class rather than an instance of the class. While both of these are syntactically similar, they serve different purposes and have distinct behaviours.
🌐
Quora
quora.com › Are-there-any-performance-implications-of-declaring-a-class-method-versus-a-static-method-in-Python
Are there any performance implications of declaring a class method versus a static method in Python? - Quora
Because it’s a class method, Python automatically sends a reference to the class as the first parameter. (In Python, that parameter is typically called cls, but Python does not require you to give it that name). The function foo(), on the other hand, is a static method.
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.3 documentation
2 weeks ago - A static method does not receive an implicit first argument. To declare a static method, use this idiom: class C: @staticmethod def f(arg1, arg2, argN): ...
🌐
Medium
medium.com › @ryan_forrester_ › class-methods-vs-static-methods-in-python-a-clear-guide-47fcfd385e27
Class Methods vs Static Methods in Python: A Clear Guide | by ryan | Medium
November 4, 2024 - Key differences: 1. Class methods receive the class as the first argument (`cls`) 2. Static methods don’t receive any automatic arguments 3. Class methods can access and modify class state 4.
🌐
GitConnected
levelup.gitconnected.com › python-advanced-interview-method-vs-function-or-staticmethod-vs-classmethod-b2e9aef51f97
Python Advanced Interview: Method vs Function (or Staticmethod vs Classmethod) | by Jonathan Nifenecker | Level Up Coding
July 5, 2024 - To make sense of the “implicit first argument” you need to first understand that the method is bound to an instance (or a class). ... fn has a binding via an instance but not via the class. Hence the difference. a.fn() implicitly has a as an instance parameter of fn. The binding is done via the instance, thats why accessing it from the class directly (withthout an instance) means there cannot be any binding, and we then have a function. staticmethod never has binding.
🌐
Python Engineer
python-engineer.com › posts › difference-classmethod-and-staticmethod
Difference between @classmethod, @staticmethod, and instance methods in Python. - Python Engineer
Use this when you don't need to access variables that belong to an instance, but still need general attributes that belong to the class. Static methods can neither access class variables/methods nor instance variables/methods.