Conditionals
Python allows us to compare values using comparison operators, enabling us to make decisions based on these comparisons. This is fundamental for controlling the flow of a program.
Boolean Data Type
The result of a comparison is a Boolean value: either True or False. Booleans represent one of two possible states.
Comparison Operators
Python provides several comparison operators:
| Operator | Name | Description |
|---|---|---|
== | Equal to | Checks if two values are equal |
!= | Not equal to | Checks if two values are not equal |
> | Greater than | Checks if the left value is greater than the right value |
< | Less than | Checks if the left value is less than the right value |
>= | Greater than or equal to | Checks if the left value is greater than or equal to the right value |
<= | Less than or equal to | Checks if the left value is less than or equal to the right value |