转自: https://blog.csdn.net/fireflylane/article/details/84575211
作用
输出文件开头注释的内容
具体用法
1)momodule.py
"""THis is the module docstring."""
def f(x):
""" This is the function docstring."""
return 2 * x
2) 执行
>>> import mymodule
>>> mymodule.__doc__
' This is the module docstring.'
>>> mymodule.f.__doc__
' This is the function docstring.'
相关知识
Python有个特性叫做文档字符串,即DocString,这个特性可以让你的程序更加清晰易懂,在Python的系统文件里,也都在使用这个特性。因此推荐每个Python爱好者都使用它。
DocString是有自己的格式的。一般是放在自己函数定义的第一行,用 " 符号表示,在这 " 里面添加函数功能说明就可以了。这个说明可以使用 .doc (注意前后都是双__),将DocString特性print打印出来。
DocString的典型用法就是help()调用,它抓取DocString属性,清晰的给你展示出来。