QuestionQ72

VerifiedMiscellaneous (List Comprehensions, Lambdas, Closures, I/O)

What behavior is expected from the following code?

x = 3 % 1  
y = 1 if x > 0 else 0  
print(y)  
Explanation

The modulo operation 3 % 1 produces 0. Since x > 0 is false, the conditional expression assigns 0 to y, so print(y) outputs 0.

Community Discussion

No comments yet. Be the first to start the discussion!