Conditions
A condition lets a program choose a path. Python checks a true-or-false expression and runs only the matching indented block.
By the end of this lesson, you can:
- Write if, else, and elif
- Indent a branch
- Compare values at boundaries
- Combine requirements with and
Conditions lesson progress0%
Course progress: 0% · 0 of 11 steps completed in this module
Learn · Run code only when a condition is true
Run code only when a condition is true
An if line ends with a colon. The indented instructions below it belong to that branch. When the condition is False, Python skips that block.
Pattern
if condition:
instructionCode
age = 18
if age >= 18:
print("Adult")Output
Adult
Why it works
- age stores 18.
- >= includes 18, so the condition is True.
- The indented print runs once.
Common mistake
Not this
if age >= 18
print("Adult")Try this
if age >= 18:
print("Adult")The colon starts the block and indentation marks which instruction belongs to it.