Conditionals Recap
In this chapter, we learned how our program can decide what to do using conditions. We found out that:
- The
ifstatement executes the following block of code if its condition is true. - An
ifstatement can be followed by anelifstatement, which can have another condition that, if true, executes theelifstatement's block of code. - An
iforelifstatement can be followed by anelsestatement. The block of code for theelsestatement executes if all precedingifandelifconditions are false. - After the first true condition, the corresponding block of code is executed, and the rest of the conditional is skipped.
- Comparisons are made using the following operators:
==- Equals,!=- Not equal,>- Greater than,>=- Greater than or equal to,<- Less than,<=- Less than or equal to. - The block of code following a colon must be indented.
- There are two Boolean values:
TrueandFalse. - We can combine multiple conditions using the logical operators
andandor. - We can invert a condition using the
notoperator, changingTruetoFalseor vice versa. - Nested conditions are those that are inside the block of another condition.
Congratulations on completing the second lesson of Python! In the next lesson, we will dive into the world of arrays and explore their amazing capabilities in programming. Get ready for an adventure full of efficient data storage and manipulation!
Instructions
When you're ready, proceed to the next lesson!
Start programming for free
10/10