Python/Spyder 等同于 Javadoc 的是什么?

What is Python/Spyder equivalent of Javadoc?

Python 中的 Javadoc 等价物是什么?我想评论一些代码,如果我在另一个 class 中使用它们,我希望在悬停时显示文档。我是using/trying顺便设置Spyder

提前致谢。

这就是你在 python 中编写文档字符串的方式:

def square_root(n):
    """Calculate the square root of a number.

    Args:
        n: the number to get the square root of.
    Returns:
        the square root of n.
    Raises:
        TypeError: if n is not a number.
        ValueError: if n is negative.

    """
    pass

格式不统一,可以符合例如:

  • 休息
"""
This is a reST style.

:param param1: this is a first param
:param param2: this is a second param
:returns: this is a description of what is returned
:raises keyError: raises an exception
"""
  • Google
"""
This is an example of Google style.

Args:
    param1: This is the first param.
    param2: This is a second param.

Returns:
    This is a description of what is returned.

Raises:
    KeyError: Raises an exception.
"""
  • NumpyDoc
"""
My numpydoc description of a kind
of very exhautive numpydoc format docstring.

Parameters
----------
first : array_like
    the 1st param name `first`
second :
    the 2nd param
third : {'value', 'other'}, optional
    the 3rd param, by default 'value'

Returns
-------
string
    a value in a string

Raises
------
KeyError
    when a key error
OtherError
    when an other error
"""