在 Javascript 中,编码人员可以使用 @param
和 {string}
选项对函数进行如下注释。
Python 有一个文档字符串,但是阅读 https://www.python.org/dev/peps/pep-0257/
Docstring Conventions 我看不到与 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
}
上面的 comment 的 python 等价物是什么(如果存在的话)?
特别是 @param
和 {number}
功能....
最佳答案
在 python 中,您将在文档字符串中这样注释。
def generate_random_matrix(n, m):
"""generate a random matrix
Parameters
-----------------
n : int
the height of the matrix
m : int
the width of the matrix
Returns
----------
An array with shape (n, m)
"""
pass
有几个指南可以看看这个anwser .
关于javascript - python 是否具有与 javascript 等效的函数注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58710739/