A static method in Python is a method that:
✔ Belongs to a class
✔ Does NOT access instance (self)
✔ Does NOT access class (cls)
✔ Acts like a normal function
✔ Lives inside a class namespace
Static methods are:
Namespaced Utility Functions
They are grouped logically inside a class but have:
👉 No automatic binding
👉 No implicit arguments
Without static methods:
def add(a, b):
return a + bWith static methods:
class MathUtils:
@staticmethod
def add(a, b):
return a + b✔ Better organization
✔ Logical grouping
✔ Cleaner APIs
class ClassName:
@staticmethod
def method_name(parameters):
# logic✔ Uses @staticmethod decorator
✔ No self
✔ No cls
class MathOperations:
@staticmethod
def add(a, b):
return a + b
print(MathOperations.add(10, 20))Output:
30
✔ Called using class
✔ No object required
class Demo:
@staticmethod
def greet():
print("Hello!")
d = Demo()
d.greet()Output:
Hello!
Because static methods:
✔ Are NOT bound
✔ Behave like functions
Python simply finds method in class namespace.
class Example:
def instance_method(self):
print("Instance")
@staticmethod
def static_method():
print("Static")Instance method call:
obj.instance_method()
→ Example.instance_method(obj)Static method call:
obj.static_method()
→ Example.static_method()✔ No object passed
| Feature | Static Method | Class Method |
|---|---|---|
| First Argument | None | cls |
| Access Class Data | ❌ | ✅ |
| Access Instance Data | ❌ | ❌ |
| Binding | None | Class-bound |
| Use Case | Utility Logic | Class Logic |
class Test:
x = 10
@staticmethod
def static_show():
print(Test.x)
@classmethod
def class_show(cls):
print(cls.x)✔ Static method → Hardcoded class
✔ Class method → Dynamic class
Static methods use:
staticmethod()Which wraps function inside descriptor.
Equivalent to:
method = staticmethod(function)class Demo:
def greet():
print("Hello")
print(Demo.greet)Output:
<function Demo.greet>
✔ No bound method object
WRONG:
class Test:
def __init__(self):
self.x = 10
@staticmethod
def show():
print(self.x) ✔ No self
WRONG:
print(cls.x) ✔ No cls
print(Test.x)Works BUT:
Breaks inheritance flexibility
Better design → Use classmethod when class access needed.
Bad usage:
✔ Business logic dependent on object state
✔ Logic needing class attributes
✔ Overcomplicating design
✔ Utility/helper logic
✔ Independent calculations
✔ Logical grouping
✔ Stateless operations
✔ Validation helpers
✔ Factory helpers (sometimes)
❌ Needs instance data → Use instance method
❌ Needs class data → Use classmethod
❌ Complex workflows → Use normal methods
class Validator:
@staticmethod
def is_valid_age(age):
return 0 < age < 120
print(Validator.is_valid_age(25))Output:
True
✔ Clean utility logic
✔ Static methods = Functions inside class
✔ No automatic binding
✔ No self / cls
✔ Used for utilities
✔ Callable via class or instance
✔ Backed by descriptor protocol
✔ Avoid misuse
- Create utility static method
- Break code using
selfinside static method - Convert staticmethod → classmethod
- Compare binding behaviors
- Use staticmethod manually
- Build validation helper class
- Predict outputs