Tutorial by Examples

The spacing should be even and uniform throughout. Improper indentation can cause an IndentationError or cause the program to do something unexpected. The following example raises an IndentationError: a = 7 if a > 5: print "foo" else: print "bar" print "done&qu...
For Python, Guido van Rossum based the grouping of statements on indentation. The reasons for this are explained in the first section of the "Design and History Python FAQ". Colons, :, are used to declare an indented code block, such as the following example: class ExampleClass: #Eve...
Whitespace is handled by the lexical analyzer before being parsed. The lexical analyzer uses a stack to store indentation levels. At the beginning, the stack contains just the value 0, which is the leftmost position. Whenever a nested block begins, the new indentation level is pushed on the stack, ...

Page 1 of 1