TutorialsPythonSyntax and Indentation
Getting Started · Chapter 3

Syntax and Indentation

Learn why indentation is part of Python syntax.

Why this matters

Python uses indentation to show which statements belong together, so spacing is not merely cosmetic.

Start with the idea

A colon usually introduces a block, and the indented lines under it belong to that block. Consistent indentation makes the program structure visible.

IdeaUnderstand the purpose
CodeRun the smallest example
PracticeChange it yourself
SubjectVision learning pattern: understand the idea before memorizing syntax.

Small working example

Run this example first. Do not change several things at once; confirm the basic behavior, then experiment.

Python
temperature = 28

if temperature > 25:
    print("Warm day")

print("Done")
Expected output
Warm day
Done
What to notice

The example is intentionally small. Focus on the chapter’s main idea before adding extra syntax or framework code.

Common beginner mistake

Mistake

Mixing indentation levels so code appears visually related but Python treats it differently.

Better approach

Use consistent indentation, normally four spaces, and let your editor help.

Quick recap

  • Indentation defines blocks.
  • Colons often start blocks.
  • Readable formatting and correct structure go together in Python.

Try it yourself

These are deliberately small. If you can complete them without copying the example, you are ready to continue.

  1. Add an else block.
  2. Move print("Done") inside the if block and compare the behavior.