Question 3
Evaluate:
Hint
Work out the expression from left to right in stages.
Solution
We can split the compound expression into 3 parts:
- Part 1:
0 -
Part 2:
not 1 / (float(4//3)-4/3)By this point we can deduce mathematically that: $ \frac{1}{1.0 - \frac{4}{3}} = -3 $ Technically
1 / (float(4//3)-4/3)will produce-3.000000000000001, but the exact value in this case does not matter as much. Because-3is not aFalselike value/falsy value,not -3ornot -3.000000000000001will produceFalseimmediately. -
Part 3:
1 / (int(4/3)-4//3)
We now have 0 or False and 1/0.
0 or False evaluates to False, since neither LHS or RHS of this part of the compound expression does not evaluate to a truthy/True like value.
With False and 1/0, it evaluates to False immediately.
While 1/0 will raise a ZeroDivisionError immediately, that is not the first part of the expression that is evaluated.
Because the LHS of this expression is already known to evaluate to False, by short-hand logic, it produces False.