What does the expression 10 % 3 evaluate to in Python?

What does the expression 10 % 3 evaluate to in Python?

a) 1
b) 3
c) 0
d) 2

Answer:

d) 1

Explanation:

The % operator in Python is the modulus operator, which returns the remainder of the division of two numbers. In the expression 10 % 3, 10 is divided by 3, and the remainder is 1.

result = 10 % 3  # result is 1

The modulus operator is often used in scenarios where you need to determine if a number is even or odd (by checking n % 2) or to cycle through a sequence of values. It’s also useful in problems where you need to wrap around values, such as in circular arrays or modular arithmetic.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top