Static Methods in Python
Use @staticmethod for utility methods that logically belong to the class but do not use self or cls.
BeginnerObject-Oriented ProgramsExample 14 of 25
static-methods.py
Run in browser1# Program to demonstrate static methods23class MathUtil:4 @staticmethod5 def is_even(n):6 return n % 2 == 078print(MathUtil.is_even(4))9print(MathUtil.is_even(7))
Output
True False
What's going on
Static methods are namespaced inside the class but behave like plain functions without accessing instance or class state.