15468 发表于 2017-4-29 11:01:00

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

  在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__


版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: Python随笔之文档字符串(DocStrings)