In the previous section, we learned what an expression is. Boolean expressions are expressions that evaluate to a boolean value - either true or false.
We’ve already seen an example of boolean expressions: comparing 2 numbers.
10 > 0
is a boolean expression that uses the
comparison operator to check if 10 is greater than 0. Other comparison operators are
Python has 3 logical operators:
. Like all Python operators, these perform operations on expressions. Specifically, they can only be used on boolean expressions, and using a logical operator will result in a boolean value.
is True if both expressions are True
is True if one or both expressions are True
is True if the expression is False (it does a reversal)
4 > 5 and 6 != 10 # evaluates to False
4 < 5 and 6 != 10 # evaluates to True
4 > 5 or 6 != 10 # evaluates to True
not 4 > 5 # evaluates to True
let you tell the program how to make decisions. Every if/else statement has a boolean expression as its
if number_of_points >= 10:
print("You still need more points")
Learn about logical operators
Learn about if/else statements
No results from filter