相关疑难解决方法(0)

如何在Python中将列表扩展为函数参数

是否有语法允许您将列表扩展为函数调用的参数?

例:

# 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 arguments

138
推荐指数
4
解决办法
9万
查看次数

在不知道列表大小的情况下将列表元素分配给变量?

新手在这里.
假设您想要在不事先知道列表大小的情况下将列表元素分配给变量,您是如何做到的,特别是在Python中?
例如.list有5个元素,程序创建5个变量(var1,var2,var3,var4,var5)并为其分配元素.

python

2
推荐指数
1
解决办法
154
查看次数

标签 统计

python ×2

arguments ×1