Apply to factors as Python list

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

I want to turn over the two-dimensional list as a factor for the Python zip function, what should I do? Like the JavaScript application method.

def myFunc(a1, a2, a3):


Even if you put the factor in this way, I hope the result comes out as if you just did myFunc(1,2,3).

python list

2022-09-20 15:39

1 Answers

>>> def my_func(a1, a2, a3):
    return a1+a2+a3

>>> my_func([1,2,3])
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
TypeError: my_func() missing 2 required positional arguments: 'a2' and 'a3'
>>> my_func(*[1,2,3])
>>> a = [1,2,3]
>>> my_func(*a)

2022-09-20 15:39

If you have any answers or tips

© 2022 pinfo. All rights reserved.