indentation
The spaces at the start of a line, which in Python decide which statements belong inside a def, if, for or other block.
In more detail
All lines of one block must be indented by the same amount, conventionally four spaces. Moving a line back out, dedenting, ends the block, so indentation changes what the program means, not only how it looks. Inconsistent indentation raises IndentationError.
Related terms
- code block — The group of indented statements under a heading such as def, if, for or while, which run together as one unit.
- compound statement — A statement such as if, for, while, def, class, try or with that has a heading ending in a colon and an indented block beneath it.
- IndentationError — A kind of syntax error raised when lines are indented inconsistently or a block is missing its indented body.
Taught in
- What Python Is, And Where It Came From — Hands-on Python: Complete Video Course & Book
- A Sample Program, Explained — Hands-on Python: Complete Video Course & Book
- Integer Arithmetic And Precedence — Hands-on Python: Complete Video Course & Book
- Several Functions, And Flow Of Control — Hands-on Python: Complete Video Course & Book
- Conditions And Simple If Statements — Hands-on Python: Complete Video Course & Book
- Nesting Control Flow Statements — Hands-on Python: Complete Video Course & Book
- Interpreter, Compiler, And What Counts As Syntax — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Fundamentals Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Branching With If, Elif And Else — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Nested Loops, Traced By Hand — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Control Flow Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Functions, Return Values And Recursion — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Classes, Objects And Two Stacks — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- List Comprehensions, Filtered And Nested — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep