 # How Pandas Uses Boolean Operators

As filtering can be a bit tricky in Pandas, you’ll learn in this lesson how Pandas uses boolean operators. rworreby

I actually want to point out a section that is wrong in this video, starting from 1:00 to 1:45:

As Python uses short-circuit evaluation for algebraic expressions, the expression in the video (`4 < 3 and 5 > 4`) would be treated the following way: `4 < 3` is False and therefore the expression would return False immediately (as “False and ” is always false). The statement in the video that `4 < 3` is evaluated, then `5 > 3` is evaluated and then both compared (???) is therefore wrong.

In the next section, short-circuit evaluation is mentioned, however, in the example that is given, there is no short-circuit evaluation, as its a nested comparison. It is also wrong that `(3 and 5)` “just” evaluates to 5. In a logical test, the result is the last evaluated statement. Its not the last argument.

As a reference, check the following things:

``````(3 and 5) # Evaluates to 5, no short-circuit eval
(5 and 3) # Evaluates to 3, no short-circuit eval
(0 and 5) # Evaluates to 0, short-circuit eval
(5 and 0) # Evaluates to 0, no short-circuit eval
``````

I think in the video there is a wrong understanding of what short-circuit evaluation is. Truth tables is a thing to check out, but applied to boolean logic in python these are the base cases of short-circuit evaluation:

``````False and X # X is never evaluated
True or X # X is never evaluated

# No short-circuit
False or X # Could still evaluate to True or False overall, so X has to be evaluated
True and X # Could still evaluate to True or False overall, so X has to be evaluated
`````` Matt Williams

I don’t know that the statement above is correct, because if you perform the evaluation `5 < 3 or 3 < 4`, the output is `True`. Obviously the interpreter looked at both numerical comparisons in the operation, otherwise it would have stopped at `5 < 3` and returned false, as rworreby is suggesting above. 