javascript - python 是否具有与 javascript 等效的函数注释?

标签 javascript python node.js python-3.x docstring

在 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/

相关文章:

node.js - 异步系列nodejs中的async foreach

javascript - 如何使用 javascript 正确隐藏 XSL 处理的 XML 元素列表

Javascript SideBar 在页面更改时保持打开状态

python - 尝试学习 python 类

python - Flask-Security token 是如何创建的?

node.js - 组织expressjs路线时遇到问题

javascript - 具有多种外观的多个类上的 WrapAll()

javascript - 如何更改按钮单击 react 中的变量值

Python:查找.mp4电影的记录时间

node.js - Azure DevOps Pipeline 全局包安装最佳实践