如何 return 可变数量的值?

How to return a variable number of values?

我必须编写一个如下所示的函数:def funci(x1, ..., xki) -> y1,...,ymi,其中所有 xy 的类型都是 TypeClass。 使用 typing 模块,我可以将函数声明为:f(*args: TypeClass),但是如何定义可变长度返回值的类型?

来自typingdocumentation,

To specify a variable-length tuple of homogeneous type, use literal ellipsis, e.g. Tuple[int, ...].

在您的情况下,return 类型应为 Tuple[TypeClass, ...]