Flow control statements can decide which Python instructions to execute under which conditions.
Boolean Values
Boolean data types only have two values: True and False. When typed as Python code, they should always start with upper case, and should not be inside quotes like what is done on strings. They can also be stored in variables.
Boolean Operators
Operators: and, or and not. They evaluate expressions down to a Boolean value. The and operator evaluates an expression to True if and only if both Boolean values are True.
| The and Operator’s Truth Table | |
| Expression | Evaluation Result |
| True and True | True |
| True and False | False |
| False and True | False |
| False and False | False |
| The or Operator’s Truth Table | |
| Expression | Evaluation Result |
| True or True | True |
| True or False | True |
| False or True | True |
| False or False | False |
| The not Operator’s Truth Table (operates on only one Boolean Value) | |
| Expression | Evaluation Result |
| not True | False |
| not False | True |
Comparison Operators
| Operators | Meaning |
| == | Equal To |
| !- | Not Equal To |
| < | Less Than |
| > | Greater Than |
| <= | Less Than or Equal To |
| >= | Greater Than or Equal To |
Important points to remember with Comparison Operators
- Integer or Floating-point value will always be unequal to a string value.
- The <, >, <=, and >= operators only work properly with integer and floating point values.
- == operator asks whether two values are the same as each other.
- = operator puts the value on the right into the variable on the left (variable assignment).