Booleans, Logic, and Loops
Get an understanding of Booleans, if statement logic, for loops, and while loops.
We'll cover the following
Booleans
The last data type is bool
, short for Boolean. A bool
can only have one of two values: True
or False
. By themselves, bools are not that useful. Their usefulness comes from doing logical comparison operations like equals and does not equal. Below is a list of the logical comparisons in Python:
Operation | Python syntax |
---|---|
Equals | == |
Not equals | != |
Less than | < |
Less than or equal to | <= |
Greater than | > |
Greater than or equal to | >= |
At least one condition is true | or |
Both conditions are true | and |
Here are some examples of using logical comparisons:
Get hands-on with 1400+ tech skills courses.