1. Home
  2. Computing & Technology
  3. Python

Beginning Python: Putting It All Together With Syntax

From Al Lukaszewski, for About.com

2 of 10

Indentation

Indentation in Python counts. This may seem odd at first, but it goes a long way to making Python programs some of the easiest programs to maintain.

Every block structure -- control structures, classes, functions, etc. -- must be indented the same number of times for their level in the program. Convention is to use four spaces (without tabs) for each level of indentation. So, a skeletal structure of a Python program might look like this:

import os, re, string

def test_function1():

def test_function2():

class CartoonCharacter(object):

def main():

     a = 8
     string = "sunshine"

     if x == 1:

     if x != 1:

             if a > 0:

                while b < 100:

         elif a == 0:

         else:

     else:

if __init__ == "__main__":
     main()

Explore Python
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.