QuestenaUn entraînement qui indique quoi revoir ensuite
Question 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`.Bonne réponse
  3. It evaluates both operands and always returns `True`.
  4. It raises TypeError when `x` is not already Boolean.

Explication

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.

Continuer avec ce test

Commencer l’entraînement
Question 55: How does `x or y` behave when `x` is truthy? · Python Fundamentals · Questena