If the syntax *expression appears in the function call, expression
must evaluate to an iterable. Elements from this iterable are treated
as if they were additional positional arguments; if there are
positional arguments x1, ..., xN, and expression evaluates to a
sequence y1, ..., yM, this is equivalent to a call with M+N positional
arguments x1, ..., xN, y1, ..., yM.
是的,使用*arg将args传递给函数将使python解压arg中的值并将其传递给函数。
所以:
可以在iterable之前使用
*
运算符在函数调用中展开它。例如:(注意
*
之前的timeseries_list
)从python documentation:
python教程在一个名为Unpacking argument lists的部分中也介绍了这一点,其中还演示了如何使用字典对带有
**
运算符的关键字参数执行类似的操作。*args
只表示函数接受许多参数,通常是相同类型的。查看Python教程中的this section了解更多信息。
相关问题 更多 >
编程相关推荐