Skip to content
Learn Netverks

Lesson

Step 9/36 25% through track

control-flow-python

Control flow

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Control flow: the syntax, patterns, and safety habits you need before advancing in Python.

Coroutines replace callback hell on Android and in Ktor—structured concurrency is interview-critical.

You will apply Control flow in contexts like: Scripts, Django/FastAPI apps, notebooks, and glue code between systems.

Write Python 3 in the editor and click Run on server—the dev runner executes your script with print() for output; stdlib only in playground snippets (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Python control flow uses indentation (typically four spaces) instead of braces—unlike JavaScript or Java. Colons start blocks after if, elif, else, for, while, and def.

if / elif / else

score = 85
if score >= 90:
    grade = "A"
elif score >= 80:
    grade = "B"
else:
    grade = "C"

for and while

for item in ["a", "b", "c"]:
    print(item)

n = 3
while n > 0:
    print(n)
    n -= 1

for iterates any iterable—lists, strings, dict keys, ranges. Use range(n) for counted loops.

Important interview questions and answers

  1. Q: Truthiness in Python?
    A: Empty collections, 0, None, and False are falsy; most other objects are truthy.
  2. Q: break vs continue?
    A: break exits the loop; continue skips to the next iteration.

Self-check

  1. What syntax starts a block after if?
  2. How do you loop 0 through 4 inclusive?

Tip: Python has no switch until 3.10+ match—use if/elif chains or dict dispatch for simple cases.

Interview prep

Indentation rules?

Consistent spaces (usually 4) after : define blocks—mixing tabs and spaces causes errors.

Truthy values?

Empty collections, zero numbers, None, and False are falsy; most other objects are truthy.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • elif chain?
  • while else clause?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump