python如何查询函数

Python (176) 2023-06-23 14:37:34

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

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

如:

importrequests
help(requests)

会有类似如下输出:

相关推荐:《Python视频教程》

2、查询函数信息

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

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

如:

importrequests
dir(requests)

会有类似如下输出:

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

(1)help()方法。

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

如:

importrequests
help(requests.get)

会有类似如下输出:

(2)__doc__方法。

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

如:

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

会有如下类似输出:

print(requests.__doc__)

print(requests.get.__doc__)

THE END

发表回复