Documentation Strings

First statement of function, class, or module can be a string

  • This is known as a documentation string
  • Example:
     def factorial(n):
         """This function computes n factorial"""
         if (n <= 1): return 1
         else: return n*factorial(n-1)

Accessing documentation strings

  • Found by looking at __doc__ attribute.
     >>> print factorial.__doc__
     This function computes n factorial
     >>>
     
  • Code browsers and IDEs often look at doc-strings to help you out.
  • And it's considered to be good Python programming style.
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 32
July 17, 2000, beazley@cs.uchicago.edu
>>>