beginnerPython
What is the modulus operator?
Answer
Clear, interview-ready explanation
The modulus operator returns the remainder after division.
%
print(10 % 3)
Output:
1
It is commonly used to determine whether a number is even or odd:
number = 8
if number % 2 == 0:
print("Even number")
In Python, the modulus result follows the sign of the divisor, which is useful to remember when working with negative numbers.