Indentation

noun

say it: “in-den-TAY-shun” /ˌɪndɛnˈteɪʃən/

The spaces at the start of a line; Python uses them to group code into blocks, with every line in a block indented by the same amount, usually 4 spaces.

What is indentation in Python?

Indentation is the spaces at the start of a line. Python uses it to group code: every line in the same block is indented by the same amount, usually 4 spaces.

for name in ["Ana", "Ben"]:
    print("Hello", name)   # runs for each name
print("Done")              # runs once, after the loop

In a sentence

  • “An IndentationError means the indentation of a line doesn't match its block.”
  • “The indentation shows which lines belong to the loop.”

Level: Novice · More Python terms at this level

Updated