Python Practice › OOP Programs › Program 5

Static method

EasyOOP Programs · 5 of 48

Write a Python class with a static method.

Advertisement
Output
True False

Approach

  1. @staticmethod needs no self; it is a helper grouped with the class.

Solution

Python
class MathUtils:    @staticmethod    def is_even(n):        return n % 2 == 0 print(MathUtils.is_even(10), MathUtils.is_even(7))
Output
True False

Line by line

Lines 2-4

The method uses only its arguments, so it does not need an object.

Learn the concept

New to this topic? Read the lesson, then come back.

More oop programs

← All 48 OOP Programs

Leave a Comment