在Python中有一个奇妙的特性,文档字符串,又称为DocStrings。用它可以为我们的模块,类,函数添加说明性的文字,使程序易读易懂,更重要的是可以通过Python自带的标准方法将这些描述性文字信息输出。下面举例说明。
'''This is My own Module Date:2011-09-07 Author:Chris Mao This is description information''' class TestClass: '''This is TestClass' DocStrings''' def func1(): '''this is func1's DocStrings''' pass def func2(): '''this is func2''' print "this is func2" print func2.__doc__