The shape of code.
Indentation, comments, and the tiny rules that make your code readable.
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.
# A tiny launch sequence
ready = True
if ready:
print("Systems online")
print("Ready to build")
print("Sequence complete")Systems online Ready to build Sequence complete
03 Under the hood
- 1
The assignment stores True under the name ready. The if statement checks that value before running its block.
- 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
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
Change ready to False. Predict which message still appears, then run the script.
Reveal one possible solution +
ready = False
if ready:
print("Systems online")
print("Ready to build")
print("Sequence complete")05 Check your signal
Which line belongs to an if block?
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 ↗.