您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Python 3脚本中打印(__doc__)

在Python 3脚本中打印(__doc__)

__doc__功能中提供一些文档似乎很有用

这是真的。除功能外,文档也可以在模块中提供。因此,如果您有一个mymodule.py像这样的文件

"""This is the module docstring."""

def f(x):
    """This is the function docstring."""
    return 2 * x

您可以像这样访问其文档字符串:

>>> import mymodule
>>> mymodule.__doc__
'This is the module docstring.'
>>> mymodule.f.__doc__
'This is the function docstring.'

现在,回到您的问题:做print(__doc__)什么?简而言之:它输出模块文档字符串。如果未指定文档字符串,则__doc__认为None

python 2022/1/1 18:36:03 有232人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶