Linux/Unix > Python Essential Reference, Second Edition > 2. Lexical Conventions and Syntax > Documentation Strings | See All Titles

< BACK | Make Note | Bookmark | CONTINUE >

155117184014003188065099048180054212144238241179195140058238110137104027027054249055221165

### Documentation Strings

If the first statement of a module, class, or function definition is a string, that string becomes a documentation string for the associated object, as in the following example:

    def fact(n):
        "This function computes a factorial"
        if (n <= 1): return 1
        else: return n*fact(n-1)

Code-browsing and documentation-generation tools sometimes use documentation strings. The strings are accessible in the `_ _doc_ _` attribute of an object, as shown here:

    >>> print fact._ _doc_ _
    This function computes a factorial
    >>>

The indentation of the documentation string must be consistent with all the other statements in a definition. Furthermore, adjacent strings appearing on different lines are not concatenated to form a single documentation string.

| Last updated on 3/28/2002 Python Essential Reference, Second Edition, © 2002 New Riders Publishing

< BACK | Make Note | Bookmark | CONTINUE >

© 2002, O'Reilly & Associates, Inc.