Python:如何使用epytext记录返回多个值时的返回值?

问题描述 投票:0回答:1

一个简单的功能:

def foo():
    a = 1
    b = 2
    return a, b

你如何使用epytext风格记录(多个)返回值?

作为单个元组?

def foo():
    """
    This function
    @return (a, b): a tuple of a and b representing...
    """
    a = 1
    b = 2
    return a, b

或者为每个变量分别使用@return标签? (它甚至是“合法的”吗?)

def foo():
    """
    This function
    @return a: a int representing...
    @return b: a int representing...
    """
    a = 1
    b = 2
    return a, b
python docstring epytext
1个回答
0
投票

在Python中,一个元组文字由逗号创建,而不是parens(除了空元组文字(),这是一个特例),所以return a, b首先创建一个tuple然后返回它。 IOW,你不是“返回多个值”而只是一个tuple对象,所以答案是显而易见的。

© www.soinside.com 2019 - 2024. All rights reserved.