nerdexam
Python_Institute

PCEP-30-02 · Question #98

What value will be assigned to the x variable? ``python z = 10 y = 0 x = z > y or z == y ``

The correct answer is C. True. Option C is correct because Python evaluates z > y as 10 > 0, which is True, and since the or operator returns True as soon as it finds the first truthy operand (short-circuit evaluation), the expression resolves to True without even needing to check z == y. Why A (1) is wrong…

Question

What value will be assigned to the x variable?
z = 10
y = 0
x = z > y or z == y

Options

  • A1
  • BFalse
  • CTrue

How the community answered

(50 responses)
  • A
    6% (3)
  • B
    16% (8)
  • C
    78% (39)

Explanation

Option C is correct because Python evaluates z > y as 10 > 0, which is True, and since the or operator returns True as soon as it finds the first truthy operand (short-circuit evaluation), the expression resolves to True without even needing to check z == y.

Why A (1) is wrong: Python 3 boolean expressions return the actual boolean objects True or False, not integers. While True == 1 holds numerically, the assigned value is the boolean True, not the integer 1.

Why B (False) is wrong: z > y (10 > 0) is True, so the or expression immediately returns True. For the result to be False, both operands would need to be falsy - which isn't the case here.

Memory tip: Think of or as a "one winner takes all" operator - if the left side is truthy, it wins and the whole expression is truthy. Only when the left side fails does Python bother checking the right side.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice