python的doc函数 python _doc_用法

Python print(print_max.__doc)是None

__doc__是函数文档,一般作为介绍函数大概用法(当然你可以根据你的需求给函数文档),函数文档实质上是一个字符串对象,而你定义的函数并没有字符串,所以是None。

创新互联是由多位在大型网络公司、广告设计公司的优秀设计人员和策划人员组成的一个具有丰富经验的团队,其中包括网站策划、网页美工、网站程序员、网页设计师、平面广告设计师、网络营销人员及形象策划。承接:做网站、网站设计、网站改版、网页设计制作、网站建设与维护、网络推广、数据库开发,以高性价比制作企业网站、行业门户平台等全方位的服务。

比如:

请问Python 中 函数的doc string 是什么意思

其实你可以看做是函数(方法)的说明,python中的库函数多半都有很全的说明,方便使用。自己写函数的时候,通常在函数名下方用''' ''',来自己写文档的描述

python中的_doc_是什么意思?

您好,首先您描述有误,应该是__doc__,双下划线。

每个对象都会有一个__doc__属性,用于描述该对象的作用。在一个模块被import时,其文件中的某些特殊的字符串会被python解释器保存在相应对象的__doc__属性中。比如,一个模块有模块的__doc__,一个class或function也有其对应的__doc__属性。在python中,一个模块其实就是一个.py文件。在文件中特殊的地方书写的字符串就是所谓的docstrings,就是将被放到__doc__的内容。这个“特殊的地方”包括:

1. 一个文件任何一条可执行的代码之前  #模块的__doc__

2. 一个类,在类定义语句后,任何可执行代码前#类的__doc__

3. 一个函数,在函数定义语句后,任何可执行代码前#函数的__doc__

举个例子:

#use  __doc__ 属性

class MyClass:

'string.'

def printSay():

'print say welcome to you.'

print 'say welcome to you.'

print MyClass.__doc__

print MyClass.printSay.__doc__

#输出结果

string.

print say welcome to you.

python中的_doc_是什么

文档字符串。注意,是 __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"

更详细的资料请参考 Python Tutorial 4.7.6 Documentation Strings.


分享题目:python的doc函数 python _doc_用法
文章路径:http://myzitong.com/article/doegpjd.html