代码之家  ›  专栏  ›  技术社区  ›  PyRsquared

返回多个值的python docstring约定是什么?

  •  0
  • PyRsquared  · 技术社区  · 7 年前

    假设我有一个返回多个值的函数

    import numpy as np
    def add_and_raisepower(x, y):
        """
        1) Add inputs **x** and **y** and return the result.
    
        2) Raise **x** to the power of **y**, multiply this
        result by an array of one's and return the result.
    
        :type x: float
        :param x: The first input number
    
        :type y: float
        :param y: The second input number
    
        :rtype val1: float
        :rtype val2: numpy.array(float)
        """
    
        val1 = x + y
        val2 = np.ones(100)*(x**y)
    
        return val1, val2
    

    :rtype: 文档字符串中的注释;如果函数返回多个值(如本例所示),则 是否写入文档字符串(根据PEP-8)?

    :rtype: 写得像

    """
    ...
    
    :rtype: int
    """
    

    我明白,理想情况下,我应该尝试将我的函数分解为更简单的函数,这对于 add_and_raisepower 然而,在上面,我只是用这个玩具的例子来说明这个问题。

    1 回复  |  直到 7 年前
        1
  •  4
  •   user6035995 user6035995    7 年前

    :rtype: (float, numpy.array(float))
    
    推荐文章