QuestenaÜben und erkennen, was als Nächstes dran ist
Frage 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`.Richtige Antwort
  3. It evaluates both operands and always returns `True`.
  4. It raises TypeError when `x` is not already Boolean.

Erklärung

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.

Mit diesem Test weitermachen

Übung starten
Frage 55: How does `x or y` behave when `x` is truthy? · Python Fundamentals · Questena