Apply to factors as Python list

Asked 2 years ago, Updated 2 years ago, 43 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):
    do_something(...)

myFunc.some_method([1,2,3])

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>
    my_func([1,2,3])
TypeError: my_func() missing 2 required positional arguments: 'a2' and 'a3'
>>> my_func(*[1,2,3])
6
>>> a = [1,2,3]
>>> my_func(*a)
6


2022-09-20 15:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.