Module 0.2.0 - Booleans & Conditionals

  • learn about the boolean datatype

  • how to run code based on certain conditions

0.2.1 - Boolean Values

True - value exists and is correct
False - value doesn't exist and is wrong
None - value is absent

0.2.2 - Boolean Operators

== - equal to
!= - not equal to
<  - less than
>  - greater than
<= - less than or equal to
>= - greater than or equal to

Example:

print(True == True)
>>> True

print(True == False)
>>> False

print(1 == 2)
>>> False

print(5 <= 10)
>>> True

0.2.3 - If Statement

  • runs expression[s] if a condition is true

  • code that runs if a condition is true[expression] is tabbed under the conditonal

  • this area of tabbed code is the scope

"if" statements can be nested

0.2.4 - Else Statement

runs code if the aforementioned "if" statement is false

0.2.5 - Elif [Else if] Statement

a chain of "if" "else" statements

"elif" statement, a shortcut for connecting mulitiple "if" "else" statements

0.2.6 - Boolean Logic

runs code if multiple conditions are true

  • boolean operations follow the mathematical "Order of Operations" [PEMDAS]

  1. and the "and" operator takes two arguments, if both are true it will return as true

  1. or the "or" operator takes two arguments, if one or both are true it will return as true

  1. not the "not" operator takes one argument and inverts its boolean value

  1. in the "in" operator takes two arguments, if the first argument exists in the second argument, it will return as true

0.2.7 - Ternary Operator

create value based on a rule or condition

0.2.8 - Helpful Boolean Syntax