Chapter 2.3 - And / Or

An if statement can check multiple conditions by chaining together comparisons with and and or. These are also considered to be operators just like + or - are.

# And 
if a < b and a < c:
    print("a is less than b and c")

# Non-exclusive or
if a < b or a < c:
    print("a is less than either b or c (or both)")

A common mistake is to omit a variable when checking it against multiple conditions. The code below does not work because the computer does not know what to check against the variable c. It will not assume to check it against a.

# This is not correct
if a < b or < c:
    print("a is less than b and c")