Last reviewed
Correct answer: D. Using indentation (whitespace)
Explanation
Where C, Java and JavaScript use braces to mark where a block begins and ends, Python uses the whitespace itself. The language reference is explicit about it: "Leading whitespace (spaces and tabs) at the beginning of a logical line is used to compute the indentation level of the line, which in turn is used to determine the grouping of statements." Indentation is not a style preference a formatter tidies up later; it is syntax the parser reads, which is why the reference can state flatly that "The clause headers of a particular compound statement are all at the same indentation level."
The consequence you will meet in real code arrives the first time you paste a snippet from a web page into a file your editor indents with tabs. Python raises a TabError, documented as "Raised when indentation contains an inconsistent use of tabs and spaces," because those lines can mean two different things depending on how wide a tab is. Pick one convention, four spaces, and let your editor enforce it. An IndentationError is then rarely mysterious: it is the parser telling you your block boundaries disagree.
Sources
“Leading whitespace (spaces and tabs) at the beginning of a logical line is used to compute the indentation level of the line, which in turn is used to determine the grouping of statements.”
“The clause headers of a particular compound statement are all at the same indentation level.”
“Raised when indentation contains an inconsistent use of tabs and spaces.”
Practise 3 questions on this topic
Take Python Basics — Timed Test (3 questions) — scored instantly, explanation for every question, no login.