Python Bibliotheca
Python resources for teachers and students.

Commenting your code

Commenting your programs is an important step to ensuring that your code is easy to read and maintain. Here are some guidelines to commenting your code in this class.

Program header

Use a documentation string at the top of your code to identify yourself and provide other details about the assignment. The following is a good model to follow:

"""
  Author:     Guido van Rossum <guido@python.org>,
              Donald Knuth <don@knuth.org>,
              Linus Torvalds <linus@transmeta.com>
  Program:    Pig Latin Translator
  Class:      Introduction to Computer Programming
  Instructor: Mr. Wilson
  Date:       Oct. 29, 2001

  Description:  This program implements a simple English to Pig
                Latin translator.

  Contributions:  Guido - basic user interface,
                          invented Python programming language
                  Don - designed initial translate function
                  Linus - added code to handle punctuation and 
                          capital letters
"""

Program comments

The definitive guide to commenting your code is the Python Style Guide by Python's inventor Guido van Rossum. Please follow his suggestions.

[ Copyright 2005, Tim Wilson ]

Comments, questions, or suggestions? Email the webmaster