Home / Python Fundamentals / If / Else
Lesson 5 of 8

If / Else

Concept

Control flow — making decisions in code. if checks a condition, elif adds more checks, else catches everything else. Indentation matters — Python uses it to know what's inside the block.
m3shdup/app/dispatch.py
status = "online"
active_tasks = 1
max_concurrent = 2

if status != "online":
    print("Agent offline, skip")
elif active_tasks >= max_concurrent:
    print("Agent at capacity")
else:
    print("Agent available for dispatch")

What's happening

This is the core logic in your dispatch system. Python checks conditions top to bottom — the first one that's True wins. != means 'not equal', >= means 'greater than or equal to'. The indented lines (4 spaces) only run if their condition is True.

Quick Check — 3 questions

1. What does != mean?

2. When does else run?

3. Why does indentation matter in Python?