if the first condition is false, which means no matter what the second condition is output will be false. So will the second condition get computed ?
if a > b and b > c:
do something ...
if the first condition is false, which means no matter what the second condition is output will be false. So will the second condition get computed ?
if a > b and b > c:
do something ...
Python short-circuits boolean expressions. As soon as the result of the entire expression is known, evaluation stops.
If you're using and
and the left-hand expression is False
, the entire expression must be False
, so the right-hand expression wil not be evaluated.
Similarly for or
if the left-hand expression is True
, the right-hand expression will not be evaluated.
Consequently, you should be careful about including function calls with side-effects in boolean expressions. They can lead to program behavior that is difficult to predict.