Control Flow
Learn about how conditional statements and loops function in Python.
We'll cover the following
Conditional statements
Let’s first discuss conditional statements. These allow us to perform certain sets of actions in our script, depending on certain sets of other actions or flags.
For example, assume we’re making a script that takes a number from the user as input, and we want it to:
- Print
+
when the number is positive. - Print
-
when the number is negative. - Print
=
when the number is zero.
This can be achieved with the if
, elif
, and else
statements, as shown below:
Get hands-on with 1200+ tech skills courses.