Personal tools
You are here: Home CDAT Tips and Tricks Python Tips Indentation and spacing in python.
Document Actions

Indentation and spacing in python.

by Renata McCoy last modified 2007-05-08 10:18

Goal: Learn about indentation and spacing in python.



Indentation and white spaces at the beginning of a command are very inportant in python. The block of code is recognized by same indentation. Python uses carriage returns to separate statements and a colon and indentation to separate code blocks.

In the interactive mode every command must start from the first column (unless it is a comment line or a block - like commands inside a 'for' loop). In the python script file the commands do not have to start from the first column, but all have to start from the same column ( at particular level of the code block).

A note on comments:
Comments in Python start with the hash character, "#", and extend to the end of the physical line. A comment may appear at the start of a line or following whitespace or code, but not within a string literal. A hash character within a string literal is just a hash character.

 



Powered by Plone