if / elif / else Statements
Write conditional logic to branch program execution.
Introduction
Conditional statements let your program choose different execution paths based on boolean expressions.
Basic if Statement
if condition: runs the indented block when condition is truthy. Indentation (4 spaces) defines the block — no braces needed.
x = 10
if x > 0:
print('positive')All lessons in this course
- if / elif / else Statements
- for Loops and range()
- while Loops and Loop Control
- Nested Loops and Loop Patterns