Syntactically Significant Whitespace

last modified: November 24, 2014

In Python, leading spaces are significant: they denote nesting.

In C, one writes nested code within curly braces:

for (int i=0; i < 10; i++) {
        foo(i);
        bar(i);
},
notNestedAnymore();

In Python, one writes:

for i in range(0, 10):
        foo(i)
        bar(i)
notNestedAnymore()

Spaces before foo(i) and bar(i) are significant. Absence of space (dedent) before notNestedAnymore() is also significant. (Technically it's SyntacticallySignificantIndentaton; Python doesn't care about non-leading whitespace)

This enforces good indentation and therefore readability, and saves significant amount of typing (3 keystrokes per block) and vertical space.


Loading...