Flow Control Part One - Hsanokklis/2023-2024-Tech-journal GitHub Wiki

Flowchart

image

Boolean Values

Boolean Values have two values:

  • True
  • False

Info on Booleans:

  • The word Boolean is always capitalized
  • When writing Booleans in code as True or False, the true/false have to be capitalized

Comparison Operators

  • Comparison operators compare two values and evaluate down to a single Boolean value

image

image

image

Python will evaluate a number (int) and a number (str) to be false ie 42 == '42' will be false

image

image

Boolean Operators

There are 3 Boolean operators

  • and
  • or
  • not

These evaluate expressions down to a Boolean value

Binary Boolean Operators

and/or operators always take two Boolean values, so they're considered binary operators. The operator evaluates an expression to True if both Boolean values are true, otherwise it evaluates to false.

Example of true

image

Example of False

image

Truth Table

Shows every possible result of a Boolean operator

image

image

image

The not Operator

  • operates on only one Boolean value
  • evaluates to opposite the Boolean value

image

Mixing Boolean and Comparison Operators

image

  • the computer will evaluate the left Boolean first
  • Python evaluates the not operators first, then the and and then the or ones.

image