Nearby lessons
88 of 108Python - Static Methods
What Is a Static Method?
A static method is a method that does not use self or cls.
It is usually used for utility operations.
Syntax
class Demo:
@staticmethod
def add(x, y):
return x + yExample
class DurgaMath:
@staticmethod
def add(x, y):
print("The Sum:", x + y)Important Points
- Use the
@staticmethoddecorator - No implicit
selfparameter - Can be called using the class name or object reference
Summary
| Term | Meaning |
|---|---|
| @staticmethod | Defines a static method |
| self | Not required |
| cls | Not required |
🧠 Test Your Knowledge
3 QuestionsProgress: 0 / 3
Keep Going!Python - Class Methods