Conditionals
LockedLesson 5 of 60 · Syntax · Easy
Finish these first:Operators and Expressions →Or pass the tests below to unlock it now.
The big idea
An if statement lets your program make a decision. It checks a condition, and only runs the indented code underneath when that condition is True: Remember two tiny Python rules: put a colon : at the end of the if line, and indent the line underneath with 4 spaces (press Tab).
Think of it like this: Think of an `if` statement like a signpost on a trail: if the rule is true, follow the indented path underneath it.
Read the lesson
An if statement lets your program make a decision. It checks a condition, and only runs the indented code underneath when that condition is True:
score = 92
grade = ""
if score >= 90:
grade = "A"
Remember two tiny Python rules: put a colon : at the end of the if line, and indent the line underneath with 4 spaces (press Tab).
Quick check
What symbol goes at the end of a Python `if` line?
Your challenge
Write an if check: when age >= 18, set status = "adult".
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to java.conditionals (95% overlap). Same logic; Java uses braces and `&&`/`||`, Python uses indentation and `and`/`or`.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Conditionals.
Learn this first
- Operators and ExpressionsNot yet