On this page
  1. staticmethod
  2. Import & Availability
  3. Overview & Signature
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

help(staticmethod)

Linked from

Related notes