Flow Control#
When we talked about flow control in Bash script, we looked at how you can change the direction of your code. Obviously, Python has the same features in the form of the if
statement, but the syntax is a bit different:
1 2 3 4 5 6 |
|
That's an inline example (online meaning the whole if
statement is on one line.) Multiple lines are obviously possibly:
1 2 3 4 5 6 7 8 9 |
|
We can use elif
to include an else
clause, allowing us to check multiple expressions in a single statement.
The expression between if
and the final :
is called an expression. You can use any valid expression here that resolves to true (True
):
1 2 3 4 5 6 7 8 |
|
Simple, eh?