Please enable JavaScript.
Coggle requires JavaScript to display documents.
Booleans and Conditionals - Coggle Diagram
Booleans and Conditionals
Bool
a type of variable in Python
two possible values: true or false
but we do not put in true or false directly into the code, we get the vales from the boolean operators
Boolean Operators
answer yes or no questions
Comparison Operators
a equal to b
a == b
a less than b
a < b
a not equal to b
a != b
a greater than b
a > b
a less than or equal to b
a <= b
a greater than or equal to b
a >= b
can be combined with arithmetic operators
"True" and "False" must be capitalized
Combining Boolean Values
we can combine boolean values using "and", "or", and "not"
"and" is evaluated before "or"
Order of Precedence (
https://docs.python.org/3/reference/expressions.html#operator-precedence
)
adding parenthesis can also help readability
Boolean Conversion
Python has a "bool()" function which turns things into bools
Conditionals
booleans are more useful when they are combined with conditional statements
keywords are "if", "elif", and "else"
"elif" is a unique combination of "else if", and can be used as many times as you wish in a code
must remember to add colons after the end of each block of code; indent code blocks