StructuredText文档字符串中的多个返回值(Python 3)

StructuredText文档字符串中的多个返回值(Python 3),python,python-3.x,function,restructuredtext,docstring,Python,Python 3.x,Function,Restructuredtext,Docstring,我用重构的dtext文档字符串记录所有Python函数。不幸的是,我缺少描述多个返回值的方法。我找到的所有标准引用都只引用一个返回值的情况,例如or 示例: def get_linear_function_2d(p1, p2): """ Compute 2d linear function in slope-intercept form y = mx + n based on two coinciding (x,y) points. :param

我用重构的dtext文档字符串记录所有Python函数。不幸的是,我缺少描述多个返回值的方法。我找到的所有标准引用都只引用一个返回值的情况,例如or

示例:

def get_linear_function_2d(p1, p2):
    """
    Compute 2d linear function in slope-intercept form
       y = mx + n
    based on two coinciding (x,y) points.

    :param tuple p1: (x,y) tuple describing one point that lies on the line
    :param tuple p2: (x,y) tuple describing another point that lies on the line (has to differ in x)
    <START OF ISSUE: How to document?>
      :return float: slope (m)
      :return float: y-intercept (n)
    <END OF ISSUE>
    """
    assert isinstance(p1, tuple) and len(p1) == 2 and all([isinstance(val, (int, float)) for val in p1])
    assert isinstance(p2, tuple) and len(p2) == 2 and all([isinstance(val, (int, float)) for val in p2])
    assert p1[0] != p2[0]
    m = (p2[1] - p1[1]) / (p2[0] - p1[0])
    n = p1[1] - m * p1[0]
    return m, n
def get_线性函数_2d(p1,p2):
"""
以斜率截距形式计算二维线性函数
y=mx+n
基于两个重合的(x,y)点。
:param tuple p1:(x,y)描述直线上一个点的tuple
:param tuple p2:(x,y)描述线上另一个点的tuple(必须在x上有所不同)
:返回浮动:坡度(m)
:返回浮动:y截距(n)
"""
断言isinstance(p1,tuple)和len(p1)==2和all([isinstance(val,(int,float))表示p1中的val])
断言isinstance(p2,元组)和len(p2)==2和all([isinstance(val,(int,float))表示p2中的val])
断言p1[0]!=p2[0]
m=(p2[1]-p1[1])/(p2[0]-p1[0])
n=p1[1]-m*p1[0]
返回m,n
备注:针对Python 2提出了这个问题,请参阅

然而:

  • 这个问题专门针对Python2
  • 几年过去了
  • 答案与任何官方参考资料都没有联系
  • 即使没有多个返回值的官方参考,我也不清楚什么是最佳实践(两个答案都不突出)-我认为这是一个非常普遍的问题,我很想看看你们是如何解决这个缺乏标准的问题的
从技术上讲,Python没有多个返回值。在Python中,return语句中以逗号分隔的值仅表示返回一个元组值。将其记录为元组。

非常好,谢谢。也许有人应该在斯芬克斯的文档中添加一条关于这一点的评论。。。