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

How does `x and y` behave when `x` is falsy?

  1. It returns the falsy `x` without evaluating `y`.Ճիշտ պատասխան
  2. It evaluates both operands and returns `False`.
  3. It skips `x`, evaluates `y`, and returns `y`.
  4. It raises TypeError unless both operands are Boolean.

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

The falsy first operand already determines the conjunction's truth, so Python returns `x` and does not evaluate `y`. Saying that `and` always returns a Boolean loses the operand-returning behavior used by this operator.

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

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