什么是Javadoc的Python/Spyder等价物



Python中Javadoc的等价物是什么?我想评论一些代码,如果我在另一个类中使用它们,我希望在悬停时显示文档。顺便说一下,我正在使用/试图设置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

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

  • reST
"""
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
"""
  • 谷歌
"""
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
"""

最新更新