Syntactical significance of whitespace
One unusual aspect of Python's syntax is the method used to delimit program blocks. Sometimes termed "the whitespace thing", it is one aspect of Python syntax that many programmers otherwise unfamiliar with Python have heard of, since it is unique among currently widespread languages.
In languages that use the block structure ultimately derived from Algol—including Pascal, C, Perl, and many others—blocks of code are set off with braces ({ }) or keywords such as Pascal's begin and end. In all these languages, however, programmers conventionally indent the code within a block, to set it off visually from the surrounding code.
Python, instead, borrows a feature from the lesser-known language ABC—instead of punctuation or keywords, it uses this indentation itself to indicate the run of a block. A brief example will make this clear. Here are C and Python recursive functions which do the same thing—computing the factorial of an integer:
Factorial function in C:
int factorial(int x) {
if (x == 0) {
return(1);
} else {
return(x * factorial(x-1));
}
}
Factorial function in Python:
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x-1)
Some programmers used to Algol-style languages, in which whitespace is semantically empty, at first find this confusing or even offensive. A few have drawn unflattering comparison to the column-oriented style used on punched-card