Skip to content
BENIBIX Learn

Indentation

Development🧩 Programming ConceptsPrograms

Also known as Indent, Code Indentation, Tabs vs Spaces

The space at the start of a line. It shows which lines sit inside a block.

Think of it like

It is like a list with dots. The lines pushed in belong to the line above.

Example

Jack's Python code fails with an IndentationError. One line has 3 spaces instead of 4, so it does not line up.

Why it matters

Good indentation shows the shape of the code at a glance. In Python, it decides what the code does.

Definition

Indentation is the space at the start of a line of code. It shows which lines belong inside a block. In most languages it only helps people read. In Python it is part of the rules, and wrong spacing is an error. Python's style guide asks for 4 spaces per level.

Example code

python
for name in names:
    print(name)
print("done")
The pushed-in line runs for each name. The last line runs once, after the loop.
Indentation pushes the block's lines in by 4 spaces. That is how Python knows they belong to the if.

Common mistake

Mixing tabs and spaces. They can look the same on screen, and Python refuses to run the mix.

Key takeaways

  1. 1
    Shows nesting. Deeper lines sit inside outer ones.
  2. 2
    Rule in Python. Wrong spacing is an error there.
  3. 3
    Pick one style. Spaces or tabs, never both.

Learn it properly