为了账号安全,请及时绑定邮箱和手机立即绑定

python中的_doc_是什么

python中的_doc_是什么

婷婷同学_ 2018-07-05 09:09:20

1 回答

?
aluckdog

TA贡献1847条经验 获得超7个赞

文档字符串。注意,是 __doc__ ,前后各两个下划线。

一般而言,是对函数/方法/模块所实现功能的简单描述。但当指向具体对象时,会显示此对象从属的类型的的文档字符串。(示例见以下 a.__doc__)

>>> str.__doc__
"str(string[, encoding[, errors]]) -> str\n\nCreate a new string object from the given encoded string.\nencoding defaults to the current default string encoding.\nerrors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'."

>>> import math
>>> math.__doc__
'This module is always available.  It provides access to the\nmathematical functions defined by the C standard.'

>>> a = [1]

>>> a.count.__doc__
'L.count(value) -> integer -- return number of occurrences of value'
>>> a.__doc__
"list() -> new empty list\nlist(iterable) -> new list initialized from iterable's items"

为自定义的函数创建 __doc__ 的方法示例:

>>> def func():
    """Here's a doc string"""
    pass
>>> func.__doc__
"Here's a doc string"


查看完整回答
反对 回复 2018-07-26

添加回答

代码语言

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号