6.3. Working with Docstrings
Every Python module has a variable called __doc__ associated with it. This variable holds any embedded documentation created by the programmer for the module. You can create documentation for a module by entering a string at the very top of the module file.
Moreover, if the first thing you type into a class/method/function or module is a string, it will become the documentation string associated with that class/method/function or module. Here is a SimpleInterest calculator with embedded documentation.
CD-ROM reference=6012.txt
>>> def SimpleInterest(p,t,r):
... "Simple Interest Rate Calculator"
... return (p * t * r)/100
We can interrogate the SimpleInterest function with our trusty dir command.
CD-ROM reference=6013.txt ...
Get XML Processing with Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.