Skip to content

Static Method

In one line

@staticmethod is a class method that takes no self/cls — just a function grouped inside a class for organization.

In simple words

A @staticmethod is a method that doesn't receive the instance (self) or the class (cls) as its first argument. It behaves like a regular function that happens to live inside a class for organizational purposes.

Use static methods when:

  • The logic is related to the class but doesn't need instance/class data
  • You want to namespace a utility function under a class
  • The method would work identically as a standalone function

You can call it on the class (ClassName.method()) or an instance (instance.method()). It cannot access or modify instance or class state.

Example

python
class MathUtils:
    @staticmethod
    def is_even(n):
        return n % 2 == 0
    
    @staticmethod
    def average(numbers):
        return sum(numbers) / len(numbers)

# Call on class — no instance needed
print(MathUtils.is_even(4))      # True
print(MathUtils.average([1, 2, 3]))  # 2.0

# Can also call on instance (uncommon)
m = MathUtils()
print(m.is_even(5))  # False

@staticmethod takes no self/cls. It's a plain function in the class namespace — callable without an instance.

Common confusions

  • Confused with: class method

    The difference: @staticmethod receives no implicit first argument (no self, no cls) — it's a plain function. @classmethod receives cls (the class) as first arg — it can access/modify class state and works well with inheritance and alternative constructors.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary