Creating Beautiful Code with an Interpreted, Dynamically Typed Language

Python is an interpreted, dynamically typed language. Python uses indentation to create readable, even beautiful code. With Python’s vast array of built-in libraries, it can handle many jobs without the need for further libraries, allowing you to write useful code almost immediately. But Python's extensive network of external libraries makes it easy to add functionality based on your needs.

Language Features

Programming as Guido Intended It...

Indentation rules in Python. There are no curly braces, no begin and end keywords, no need for semicolons at the ends of lines - the only thing that organizes code into blocks, functions, or classes is indentation. If something is indented, it forms a block with everything indented at the same level until the end of the file or a line with less indentation.
While there are several options for indentation, the common standard is 4 spaces per level:
def function_block():
    # first block stuff
    # second block within first block:
        # second block stuff
        for x in an_iterator:
            # this is the block for the for loop
            print x
        # back out to this level ends the for loop
    # and this ends the second block...
# more first block stuff
def another_function_block():

Comments and Docstrings

To mark a comment from the current location to the end of the line, use a pound sign, '#'.
# this is a comment on a line by itself
x = 3    # this is a partial line comment after some code
For longer comments and more complete documentation, especially at the beginning of a module or of a function or class, use a triple quoted string. You can use 3 single or 3 double quotes. Triple quoted strings can cover multiple lines and any unassigned string in a Python program is ignored. Such strings are often used for documentation of modules, functions, classes and methods. By convention, the "docstring" is the first statement in its enclosing scope. Following this convention allows automated production of documentation using the pydoc module.
 In general, you use one line comments for commenting code from the point of view of a developer trying to understand the code itself. Docstrings are more properly used to document what the code does, more from the point of view of someone who is going to be using the code
Python is the sort of language that you can just dive into, so let's dive in with this example Python script:
#! /usr/bin/env python
""" An example Python script
    Note that triple quotes allow multiline strings
"""
# single line comments are indicated with a "#"
import sys         # loads the sys (system) library
def main_function(parameter):
    """ This is the docstring for the function """
    print " here is where we do stuff with the parameter"
                print parameter
    return a_result     # this could also be multiples
if __name__ == "__main__":
    """ this will only be true if the script is called 
        as the main program """
    # command line parameters are numbered from 0 
    # sys.argv[0] is the script name
    param = sys.argv[1]    # first param after script name
    # the line below calls the main_function and 
    # puts the result into function_result
    function_result = main_function(param)