Chapter 5. Logic, Comparisons, and Conditions
Our exploration of the Python language started with expression statements and the assignment statement. We can view output using the print()
function as a simple statement. We can gather input using the input()
function in an assignment statement. In order to process data conditionally, we need the if
statement.
In order to look at the if
statement, we'll need to look at Boolean data and Boolean operators. The and
, or
, not
, and if-else
Boolean operators have a "short-circuit" behavior: if the result is defined by just the left-hand operand, the right-hand side is not evaluated. This is an important feature of these logic operators. (The if-else
operator is formally called the Boolean expression, but ...
Get Python Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.