Unlike a regular instance method or a classmethod, a staticmethod doesn't automatically receive a reference to the instance or the class — it's called with only the arguments you explicitly pass. It's used for functionality that's logically related to a class, so it makes sense to group it there for organization, but doesn't need to read or modify any instance or class state at all. In practice, a lot of code that could be a staticmethod is just as reasonably a standalone module-level function; @staticmethod is chosen mainly for namespacing and discoverability.
1Understanding Static Methods (@staticmethod)
Unlike a regular instance method or a classmethod, a staticmethod doesn't automatically receive a reference to the instance or the class — it's called with only the arguments you explicitly pass. It's used for functionality that's logically related to a class, so it makes sense to group it there for organization, but doesn't need to read or modify any instance or class state at all. In practice, a lot of code that could be a staticmethod is just as reasonably a standalone module-level function; @staticmethod is chosen mainly for namespacing and discoverability.
If a method never uses self or cls anywhere in its body, that's usually a sign it should be a @staticmethod, or even a plain top-level function, rather than a regular instance method.
class MathUtils:
@staticmethod
def is_even(n):
return n % 2 == 0
print(MathUtils.is_even(4))
print(MathUtils.is_even(7))2Practical Example
Here is a real-world application of Static Methods (@staticmethod) showing how it is used in production Python code.
class TemperatureConverter:
@staticmethod
def celsius_to_fahrenheit(c):
return c * 9 / 5 + 32
print(TemperatureConverter.celsius_to_fahrenheit(100))3Best Practices
Follow these guidelines when working with Static Methods (@staticmethod):
1. Use @staticmethod for helper logic that's conceptually related to the class but doesn't touch self or cls at all
2. Consider whether a staticmethod would be just as clear (or clearer) as a plain module-level function, since the class namespace is mainly a matter of organization here
3. Reach for @classmethod instead if the method actually needs to create or reference the class itself, such as an alternative constructor
Tip: If a method never uses self or cls anywhere in its body, that's usually a sign it should be a @staticmethod, or even a plain top-level function, rather than a regular instance method.
class MathUtils:
@staticmethod
def is_even(n):
return n % 2 == 0
print(MathUtils.is_even(4))
print(MathUtils.is_even(7))