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

In `a if condition else b`, which result expressions are evaluated?

  1. Both `a` and `b` before the condition
  2. Neither result expression; it returns the condition
  3. Always `a`, because the `else` part is optional
  4. Only `a` or `b`, whichever the condition selectsՃիշտ պատասխան

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

Python tests the condition and evaluates only the result expression selected by that truth value. Evaluating both `a` and `b` first would destroy the construct's lazy branch behavior and could trigger effects from an unselected path.

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

Սկսել վարժանքը
Հարց 57: In `a if condition else b`, which result expressions are… · Python Fundamentals · Questena