Python随笔之文档字符串(DocStrings)

来源:互联网 发布:怎么打开企业淘宝店铺 编辑:程序博客网 时间:2024/06/01 09:55

在Python中有一个奇妙的特性,文档字符串,又称为DocStrings。用它可以为我们的模块,类,函数添加说明性的文字,使程序易读易懂,更重要的是可以通过Python自带的标准方法将这些描述性文字信息输出。下面举例说明。


'''This is My own ModuleDate:2011-09-07Author:Chris MaoThis is description information'''class TestClass:    '''This is TestClass' DocStrings'''    def func1():        '''this is func1's DocStrings'''        passdef func2():    '''this is func2'''    print "this is func2"print func2.__doc__

原创粉丝点击