staticmethod() Static method decorator

Last updated: 2026-09-22

staticmethod() Static method decorator

@staticmethod marks a method that receives neither self nor cls.

CategoryBuilt-in Functions
KindBuilt-in Function
Python Versionall

📝 Syntax

@staticmethod
def func(...):

⚙️ Parameters

func RequiredThe 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
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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏