您的位置 首页 > 数码极客

如何看懂python的help——如何卸载Python…

Python help函数用于显示模块,函数,类,关键字等的文档。

帮助函数具有以下语法:

help([object])

如果传递帮助函数时没有参数,则交互式帮助实用程序将在控制台上启动。

让我们在python控制台中检查print函数的文档。

help(print)

它提供以下输出:

Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='\n', file=, flush=False) Prints the values to a stream, or to by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current . sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.

也可以为用户定义的函数和类定义帮助函数输出。docstring(文档字符串)用于文档。它嵌套在三个引号中,是类、函数或模块中的第一个语句。

让我们定义一个带有函数的类:

class Helper: def __init__(self): '''The helper class is initialized''' def print_help(self): '''Returns the help description''' print('helper description') help(Helper) hel)

在运行上述程序时,我们得到第一个帮助函数的输出,如下所示:

Help on class Helper in module __main__: class Helper) | Methods defined here: | | __init__(self) | The helper class is initialized | | print_help(self) | Returns the help description | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) Help on function print_help in module __main__: print_help(self) Returns the help description

责任编辑: 鲁达

1.内容基于多重复合算法人工智能语言模型创作,旨在以深度学习研究为目的传播信息知识,内容观点与本网站无关,反馈举报请
2.仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证;
3.本站属于非营利性站点无毒无广告,请读者放心使用!

“如何看懂python的help,如何卸载Python,如何看懂python的库,如何安装python,如何卸载python,如何用python画图”边界阅读