CKTIS / Python
staticmethod()
Stores a function on a class without binding the instance or class as an implicit first argument.
Version: Python 3.14; repository image, production runtime not attested
Syntax
@staticmethod
def double(value):
return 2 * valueStores a function on a class without binding the instance or class as an implicit first argument.
The same parameter list works through the class and an instance, making namespace-local utility functions possible.
The staticmethod descriptor retrieves its wrapped function without inserting an implicit self or cls. The class call passes only 3 and produces 6; the instance call passes only 4 and produces 8. The function can still take any explicitly declared arguments. This keeps a utility in the class namespace.
class Meter:
@staticmethod
def double(n): return n*2
assert Meter.double is Meter().double and Meter.double(3) == 6
Examples
class Meter:
@staticmethod
def double(value):
return 2 * value
print(Meter.double(3), Meter().double(4))
Result
6 8
The staticmethod descriptor retrieves its wrapped function without inserting an implicit self or cls. The class call passes only 3 and produces 6; the instance call passes only 4 and produces 8. The function can still take any explicitly declared arguments. This keeps a utility in the class namespace.