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.
它是Python中的Argument Unpacking特性。你知道吗
下面是一个简单的例子:
所以
print(*(1,2,3))
等价于print(1,2,3)
请参阅python的Expressions reference
列表的值正在由*运算符解包。以下是文档中的引用:
Range返回一个元组,该元组由函数调用中的*展开。它相当于print(1,2,3,sep='')。*用于解包未命名的参数。因为它们总是被传递给第一个关键字arg,所以只要任何arg没有得到2个值,就仍然允许使用它们。你知道吗
相关问题 更多 >
编程相关推荐