如何用参数记录方法?
发布于 2021-01-29 17:57:13
如何使用Python的文档字符串使用参数记录方法?
编辑: PEP 257给出了这个例子:
def complex(real=0.0, imag=0.0):
"""Form a complex number.
Keyword arguments:
real -- the real part (default 0.0)
imag -- the imaginary part (default 0.0)
"""
if imag == 0.0 and real == 0.0: return complex_zero
...
这是大多数Python开发人员使用的约定吗?
Keyword arguments:
<parameter name> -- Definition (default value if any)
我期待一些更正式的东西,例如
def complex(real=0.0, imag=0.0):
"""Form a complex number.
@param: real The real part (default 0.0)
@param: imag The imaginary part (default 0.0)
"""
if imag == 0.0 and real == 0.0: return complex_zero
...
环境 :Python 2.7.1
关注者
0
被浏览
52
1 个回答
-
根据我的经验,numpy的文档字符串公约(PEP257超集)是最广泛的传播 遵循 惯例,它们也通过工具,如支持的狮身人面像。
一个例子:
Parameters ---------- x : type Description of parameter `x`.