Python for Data Analytics • Lesson 12
Conditional Statements
Learn how Python makes decisions using conditions. Work with if, elif and else, and apply them to real-world data analytics situations.
0 of 8 concepts completed
Complete the activity and related MCQ to unlock the next concept.
The if Statement
An if statement runs a block of code only when its condition is True. The condition is followed by a colon, and the body of the if is indented.
Learn by Seeing
Run code only when True
age = 20
if age >= 18:
print("Adult")Python checks the condition, then decides whether to run the indented block.
Edit age — see whether the if body would run:
if 20 >= 18:
print("Adult") ← runs
Interactive Activity
What does age >= 18 evaluate to when age = 20?
Hint: 20 is at least 18.
Python Analyst Mindset
Business rules become conditionals
Every "High Value" label, "Bonus Eligible" flag, and "Top Performer" tag is a conditional statement under the hood. Once you can translate a rule into if / elif / else, you can express any business policy in code.
Read the rule
What thresholds matter?
Order branches
Highest threshold first.
Add else
Handle everything below.
Test values
Check boundaries (≥ vs >).
Frequently Asked Questions
Conditional Statements — FAQs
Python uses indentation to define the body of if / else blocks. Missing indentation causes an IndentationError.
Yes. Chain as many elif as you need, and end with an optional else. Python stops at the first matching condition.
Nothing runs unless you included an else. Add an else to handle the fallback case.
Yes, and it is common. Just remember to keep the indentation consistent so Python knows which block each if belongs to.
Lesson Summary
What you learned
Runs when its condition is True.
Runs when the preceding condition is False.
Checks another condition after a False one.
and / or / not combine comparisons inside an if.
Inner conditions only run after outer ones pass.
= assigns; == compares.