Python Practice › OOP Programs › Program 5
Static method
Write a Python class with a static method.
Output
True False
Approach
@staticmethodneeds noself; it is a helper grouped with the class.
Solution
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.