在Javascript中,编码器可以使用@param
和{string}
选项对函数进行如下注释。你知道吗
Python有一个docstring,但是在阅读https://www.python.org/dev/peps/pep-0257/
docstring约定时,我看不到与js等价的东西。你知道吗
下面是一个注释JS函数的示例:
/**
* generate a random matrix
* @param {number} n the height of the matrix
* @param {number} m the width of the matrix
*/
function generateRandomMatrix(n, m) {
mtrx = []
for (let i = 0; i < n; i++) {
mtrx.push([])
for (let j = 0; j < m; j++) {
mtrx[i].push(Math.round(Math.random()*10))
}
}
return mtrx
}
上面的注释的python等价物是什么(如果存在)?
特别是@param
和{number}
特性。。。。你知道吗
是的。它们被称为docstring。见https://www.python.org/dev/peps/pep-0257/
关于Python函数参数的注释也应该包含在docstring中,然后您可以使用Sphinx自动生成文档。Sphinx最初是为Python文档本身创建的。你知道吗
默认情况下,Sphinx采用以下docstring格式(请参见here):
但是您可以使用Napoleon extension for Sphinx来读取可读性更高(因此是Pythonic)Google Style Docstrings:
在python中,您将在docstring中这样注释。你知道吗
有几条指导方针来看看这个anwser。你知道吗
相关问题 更多 >
编程相关推荐