Indentation

Indentation used to denote bodies of functions, conditionals, loops, etc.

  • Amount of indentation is arbitrary
  • Must be consistent within the same block.
     if a:
           statement1         # Consistent indentation
           statement2
     else:
           statement3         # Inconsistent indentation
               statement4     # Error!
     

Can also place on the same line

     if a: statement1
     else: statement2

Tabs

  • Expanded into number of spaces needed to move to the next column that is a multiple of 8.
  • Example: Tab in column 11 moves ahead to column 16.
  • Try to avoid tabs if you can (use emacs mode).
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 27
July 17, 2000, beazley@cs.uchicago.edu
>>>