【发布时间】:2019-11-05 11:47:40
【问题描述】:
在 Javascript 中,编码人员可以使用 @param 和 {string} 选项对函数进行如下注释。
Python 有一个文档字符串,但阅读 https://www.python.org/dev/peps/pep-0257/ 文档字符串约定我看不到与 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} 功能......
【问题讨论】:
标签: javascript python node.js python-3.x docstring