QuestenaՎարժանք, որը ցույց է տալիս՝ ինչ կրկնել հաջորդիվ
Հարց 55

How does `x or y` behave when `x` is truthy?

  1. It evaluates `y` first and returns `y`.
  2. It returns the truthy `x` without evaluating `y`.Ճիշտ պատասխան
  3. It evaluates both operands and always returns `True`.
  4. It raises TypeError when `x` is not already Boolean.

Բացատրություն

The truthy first operand already determines that the expression succeeds, so Python returns `x` and skips evaluation of `y`. Always evaluating both sides would violate short-circuit behavior, and forcing a Boolean result would discard the selected operand.

Շարունակեք այս թեստով

Սկսել վարժանքը
Հարց 55: How does `x or y` behave when `x` is truthy? · Python Fundamentals · Questena