staticmethod() Static method decorator
Last updated: 2026-09-22
staticmethod() Static method decorator
@staticmethod marks a method that receives neither self nor cls.
| Category | Built-in Functions |
|---|---|
| Kind | Built-in Function |
| Python Version | all |
📝 Syntax
@staticmethod
def func(...):
⚙️ Parameters
| func Required | The function (callable) to wrap as a static method. |
|---|
Returns:A static method descriptor; called without self or cls.
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
7
🏷️ Related Built-in Functions
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat is the difference between staticmethod and classmethod?
Astaticmethod receives no special argument and behaves exactly like an ordinary function; classmethod receives cls (the class itself) as its first argument, allowing access to class attributes.
QCan an instance call a static method?
AYes — both C().add(1, 2) and C.add(1, 2) work, with identical arguments and without automatically passing self like an instance method.
QWhy use staticmethod instead of a module-level function?
AGrouping helper functions related to the class's logic into the class's namespace organizes the code more clearly, and they can be inherited and overridden by subclasses.
QIs a @staticmethod-decorated function behaviorally different from a plain function?
ALogically no, only in 'ownership': a static method is accessed through the class and relates to class logic, while a plain function lives in the module namespace.