Python Indentation for Kids: Meaning, Not Formatting
Last updated: September 2026
Python indentation for kids is usually taught as a tidiness rule, and that is why children keep breaking it. Indentation in Python is not formatting. It is the language. The number of tabs in front of a line decides which loop that line belongs to, and moving it one level changes what the program does.
Children coming from Scratch have never met this. In Scratch, blocks physically snap inside other blocks, so containment is visible. Python replaces that with whitespace, and nobody tells them the whitespace is load-bearing.
Key Takeaways
- In Python, indentation determines which block a line belongs to. It is syntax, not style.
- Kids arriving from Scratch have to replace a visual container with an invisible one, and that transition is rarely taught explicitly.
- The fastest way to teach it is to point at each line and ask which loop it belongs to, rather than explaining scope.
- Adding or removing one tab is a real edit with a real consequence, and it is worth demonstrating deliberately.
- Tab and Shift+Tab move a line in and out one level, which most beginners never learn.
What indentation actually does
Most languages use braces to group lines together. Python uses the indentation itself, which the Python language reference treats as a formal part of the grammar rather than a convention.
That has a consequence children need stated plainly: two lines with different indentation are in different places in the program, even if they look adjacent.
Take a loop over four weeks with a loop over three days inside it:
for week in range(1, 5):
for day in range(1, 4):
print("Day", day)
print("End of week", week)
print("-------------")
Four lines, three indentation levels, and each level means something specific. The for day line sits inside the week loop, so it starts once per week. The day print sits inside the day loop, so it runs three times per week. The end-of-week print and the dashes both sit back at week level, so each fires once per week rather than once per day.
Nothing about that is visible from reading left to right. It is entirely encoded in how far each line sits from the margin.
Why Scratch kids find this hard
This is the part I think gets skipped most often.
In Scratch, a loop is a physical shape with a mouth. You drag blocks into the mouth and they are visibly held by it. If a block is inside the loop, you can see that it is inside, because it is drawn inside. Containment is a picture.
Python asks a child to hold that same relationship in their head with only whitespace as the cue. The container has no edges. A line that is inside a loop and a line that is outside it differ by four invisible spaces.
So when a child moving from Scratch to Python starts putting statements at the wrong level, they are not being careless. They have lost the visual containment they had been relying on and nobody replaced it with anything. Naming that out loud helps more than correcting the indentation does.
If your child is at that crossover point, I have written separately about when kids should switch from Scratch to Python.
Teaching it by pointing, not explaining
The method that works for me does not involve the word "scope" at all.
I put the nested loop on screen and then point at each line in turn and ask one question: which loop does this line belong to?
Not "what does this do". Not "explain the scope". Just which loop, one line at a time, working down the file. The child answers by looking at how far the line is indented, which is precisely the skill I want them to build.
With Cameron, 15, this was the best stretch of the lesson. Four lines, four questions:
- The day print belongs to the day loop
- The week print belongs to the week loop
- The day loop itself belongs to the week loop
- The dashes sit at week level, so they fire once per week, not once per day
He reasoned every one of them from the indentation. I never defined anything. By the fourth he was answering before I finished asking, which is what understanding sounds like.
The reason this works better than an explanation is that it makes the child use the cue. An explanation lets them listen to you use it.
The one-tab experiment
Once they can read the levels, change one and make them predict the result. This is the demonstration that converts indentation from a rule into a mechanism.
Take the dashes line and add a single tab so it moves inside the day loop. Before running it, ask: what changes?
The answer is that the dashes stop appearing once per week and start appearing after every single day. One keystroke, no logic touched, completely different output.
That is the moment the point lands. A tab is not decoration. A tab is an instruction about where a line lives.
Two practical things to teach alongside it:
- Tab moves a line in one level. Shift+Tab moves it back out. Most beginners spend months hitting space four times.
- Select several lines first and both still work, which saves a lot of tedium later.
One parent of a daughter starting with Scratch said the thing that worked was the challenges, because they made her figure things out for herself. Figuring it out yourself is the operative phrase. A predicted output that turns out to be right is worth more than a correct explanation delivered to a passive child.
The mistakes beginners make first
These come up with almost every student, in roughly this order.
| Mistake | What the child sees | What is actually happening |
|---|---|---|
| Statement one level too deep | It runs far more often than expected | It is inside the inner loop instead of the outer one |
| Statement one level too shallow | It runs once instead of repeatedly | It fell out of the loop entirely |
| Mixing tabs and spaces | IndentationError, or worse, silently wrong behaviour | Python cannot tell how deep the line is meant to be |
| Nothing indented after a colon | IndentationError: expected an indented block | A line ending in : must be followed by an indented line |
| Forgetting the colon | SyntaxError | The colon is what opens the block |
The mixed tabs and spaces one deserves a word. It is the most confusing of the group because the file can look perfectly aligned and still be wrong. The fix is to let the editor handle it: VS Code inserts spaces for tabs by default, and leaving that setting alone avoids the whole category.
The last two are the friendliest errors in Python, because the message says almost exactly what is wrong. Teach children to read the error text rather than scanning their code in a panic. Python's errors and exceptions guide is readable enough for a motivated teenager.
Related Articles
- When Should Kids Switch from Scratch to Python? A Tutor's Guide on timing the move that makes indentation suddenly matter.
- Python For Loops for Kids: 12 Examples That Actually Make Sense for the loops these indentation levels are organising.
- Python Debugger for Kids: Show the Loop, Don't Explain It for making the execution order visible once the structure makes sense.
Frequently Asked Questions
Why does Python care about indentation? Python uses indentation instead of braces to decide which lines are grouped together. It is part of the grammar, so changing the indentation changes the program's meaning rather than just its appearance.
How many spaces should a child use? Four spaces per level is the standard, and it is what the official PEP 8 style guide recommends. In practice, let the editor do it. Pressing Tab in VS Code inserts the right number automatically.
What is an IndentationError? It means Python could not work out which block a line belongs to. Most often a line ending in a colon was not followed by an indented line, or the indentation levels are inconsistent within a block.
Should tabs or spaces be used? Spaces, and consistently. Mixing the two is the source of the most confusing indentation bugs, because the file can look correct while being wrong. Modern editors insert spaces when you press Tab, which handles it for you.
My child keeps putting lines at the wrong level. Is that a sign Python is too early? No, it is the single most common beginner pattern, especially for children coming from Scratch where containment was visible. It resolves with practice at reading levels rather than with more explanation.
Does this apply to if statements too?
Yes. Every block in Python works the same way: if, else, for, while, and function definitions all open with a colon and contain whatever is indented beneath them. Learning it once with loops covers all of them.
The Bottom Line
Indentation is the first place where Python asks a child to keep track of something they cannot see, and treating it as a neatness rule guarantees they will keep breaking it.
Teach it as meaning. Point at lines, ask which loop each one belongs to, then move a single tab and let them watch the output change. It takes about fifteen minutes and it prevents months of confusing bugs.
I teach Python 1-on-1 to kids ages 8 to 16 online, including the Scratch to Python crossover where this usually bites. Book a free Discovery Call.
Enjoyed this article?
Your child can learn this and more with a dedicated 1-on-1 tutor.
Book a Free Discovery Call