AI engineering glossary · Python core

What is indentation?

Indentation: The leading whitespace at the start of a line, which Python uses to mark blocks of code instead of braces. Statements under an if, loop or function must be indented consistently, and four spaces is the accepted convention. Wrong indentation causes an IndentationError.

Level: beginnerTopic: Python core

Indentation: an example

In if x > 0: the next line print('positive') must be indented four spaces to belong to the if block.

Related terms

More Python core terms

Where you learn it

Indentation is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.