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

巴扎黑
发布: 2016-12-03 11:29:40
原创
1167 人浏览过

在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__
登录后复制


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!