Skip to lesson content
navan✳THE BUILD LABPYTHON 3
0/101 complete
BUILD LAB / PYTHON/ Boot sequence
EXPERIMENT 02 / 101

The shape of code.

Indentation, comments, and the tiny rules that make your code readable.

BY NAVAN SAMI◷ 6 MIN READPYTHON 3

01 The idea

Python uses indentation to group instructions. A block begins after a colon, and the indented lines belong together. Four spaces per level is the usual convention. Comments begin with # and explain the intention behind a line without being executed.

02 The experiment

Read it once. Predict what will happen. Then copy it into a .py file and run it in your local Python setup.

syntax.py
# A tiny launch sequence
ready = True

if ready:
    print("Systems online")
    print("Ready to build")

print("Sequence complete")
↳ EXPECTED OUTPUT
Systems online
Ready to build
Sequence complete

03 Under the hood

  1. 1

    The assignment stores True under the name ready. The if statement checks that value before running its block.

  2. 2

    Both indented print calls belong to the if. The final print is back at the left edge, so it runs after the block.

  3. 3

    A blank line separates ideas visually. It does not change which block an instruction belongs to. Choose useful comments: explain why, not every obvious action.

04 Your turn, builder

A SMALL MISSION

Change ready to False. Predict which message still appears, then run the script.

Reveal one possible solution +
one_possible_solution.py
ready = False

if ready:
    print("Systems online")
    print("Ready to build")

print("Sequence complete")

05 Check your signal

QUICK SIGNAL CHECK

Which line belongs to an if block?

THAT’S ANOTHER IDEA IN YOUR TOOLKIT.

Experiment. Logged.

When you can explain the idea and make the example your own, mark it complete. Your log stays in this browser.

Keep exploring

Go deeper with the official Python guide ↗.

Built with curiosity. By Navan Sami. ↗Python 3 · Think. Try. Build.