自学内容网 自学内容网

python如何查询函数

1、通用的帮助函数help()

使用help()函数来查看函数的帮助信息。

如:

import requests
help(requests)

会有类似如下输出:

2、查询函数信息

★查看模块下的所有函数:

dir(module_name)     #module_name是要查询的函数名

如:

import requests
dir(requests)

会有类似如下输出:

★查看模块下特定函数的信息

(1)help()方法。     

help(module_name.func_name)    #module_name 是模块名,func_name是模块内的函数名

如:

import requests
help(requests.get)

会有类似如下输出:

(2)__doc__方法。  

print(module_name/func_name.__doc__)        #__doc__前可以是模块名,也可以是细分到模块下的函数,两者显示不同的文档。如果是模块名,文档就是介绍模块的;如果是函数的,那就是介绍函数的。

如:

import requests
print(requests.__doc__)    #显示模块文档信息
print(requests.get.__doc__)  #显示requests模块下的get方法的文档信息

会有如下类似输出:

print(requests.__doc__)

print(requests.get.__doc__)


原文地址:https://blog.csdn.net/hakesashou/article/details/142683305

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!