首页 > 解决方案 > 放置一个“?” 在函数名之后了解更多关于函数的信息

问题描述

教科书说“要了解有关函数的更多信息,请在其名称后放置一个?。例如,键入 math.log?将在数学模块中显示对 log 函数的描述。”

我尝试在 Jupyter Notebook 中实现此示例,但出现错误。为什么?

import math
math.log?
        ^ SyntaxError: invalid syntax

标签: python

解决方案


您可以__doc__用来获取函数的文档字符串:

和 ?:

math.log?

输出:

Docstring:
log(x[, base])

Return the logarithm of x to the given base.
If the base not specified, returns the natural logarithm (base e) of x.
Type:      builtin_function_or_method

__doc__

math.log.__doc__

输出:

log(x[, base])\n\nReturn the logarithm of x to the given base.\nIf the base not specified, returns the natural logarithm (base e) of x.

推荐阅读