Static Methods

Use @staticmethod for utility methods that logically belong to the class but do not use self or cls.

BeginnerTopic: Object-Oriented Programs
Back

Python Static Methods Program

This program helps you to learn the fundamental structure and syntax of Python programming.

Try This Code
# Program to demonstrate static methods

class MathUtil:
    @staticmethod
    def is_even(n):
        return n % 2 == 0


print(MathUtil.is_even(4))
print(MathUtil.is_even(7))
Output
True
False

Understanding Static Methods

Static methods are namespaced inside the class but behave like plain functions without accessing instance or class state.

Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.

Table of Contents