staticmethod
Prev: sorted | Up: __builtins__ | Next: str
Rel: classmethod, property, super
Ref: docs.python.org — staticmethod
Tags: #public #python3 #builtins
Import & Availability
# Built-in (available globally without import)
from builtins import staticmethod
Overview & Signature
staticmethod(function, /)
Convert a function to be a static method.
Usage
class MathUtils:
@staticmethod
def clamp(val: int, lo: int, hi: int) -> int:
return max(lo, min(hi, val))
assert MathUtils.clamp(15, 0, 10) == 10
Gotchas
- Receives neither
selfnorcls: Use@classmethodinstead if the method needs to instantiateclsor read class attributes.
REPL Inspect
help(staticmethod)
Linked from
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/classmethod Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/property Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/sorted Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/str Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/super Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/c/builtins shared tags: #builtins
- tuts/c/builtins/__FILE__ shared tags: #builtins
- tuts/c/builtins/__func__ shared tags: #builtins