alw*_*btc 12 python arguments tuples list
我有一个由元组组成的列表,我想将每个元组的元素作为参数传递给函数:
mylist = [(a, b), (c, d), (e, f)]
myfunc(a, b)
myfunc(c, d)
myfunc(e, f)
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
最好的祝福
Gar*_*tty 26
这在Python中实际上非常简单,只需循环遍历列表并使用splat operator(*)将元组解压缩为函数的参数:
mylist = [(a, b), (c, d), (e, f)]
for args in mylist:
myfunc(*args)
Run Code Online (Sandbox Code Playgroud)
例如:
>>> numbers = [(1, 2), (3, 4), (5, 6)]
>>> for args in numbers:
... print(*args)
...
1 2
3 4
5 6
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19275 次 |
| 最近记录: |