Python Fundamentals / Making decisions
Lesson 15 of 38
Nested conditions
You can put an if inside another if. Keep nesting shallow: two levels is fine, five is hard to read. Combining with and often flattens it.
Key points
- Each level adds indentation
- Flatten with and/or when you can
- Early returns keep code tidy
if logged_in:
if is_admin:
print("Admin panel")Quiz · +10 XP
Why avoid deep nesting?
Log in to save progress and earn XP.