是否有语法允许您将列表扩展为函数调用的参数?
例:
# Trivial example function, not meant to do anything useful.
def foo(x,y,z):
return "%d, %d, %d" %(x,y,z)
# List of values that I want to pass into foo.
values = [1,2,3]
# I want to do something like this, and get the result "1, 2, 3":
foo( values.howDoYouExpandMe() )
Run Code Online (Sandbox Code Playgroud) 新手在这里.
假设您想要在不事先知道列表大小的情况下将列表元素分配给变量,您是如何做到的,特别是在Python中?
例如.list有5个元素,程序创建5个变量(var1,var2,var3,var4,var5)并为其分配元素.