Reputation: 7788
Is it possible to set *args
from a variable?
def fn(x, *args):
# ...
# pass arguments not as list but each as single argument
arguments = ??? # i.e.: ['a', 'b']
fn(1, arguments)
# should be equivalent to
fn(1, 'a', 'b')
Upvotes: 0
Views: 381
Reputation: 387
# pass arguments not as list but each as single argument
arguments = ??? # i.e.: ['a', 'b']
Then arguments should be assigned arguments = ['a' ,'b']
. This is argument unpacking.
Upvotes: 0
Reputation:
Yes, you can use argument unpacking (also known as splatting):
fn(1, *arguments)
Below is a demonstration:
>>> def fn(x, *args):
... return args
...
>>> arguments = ['a', 'b']
>>> fn(1, *arguments)
('a', 'b')
>>>
Upvotes: 5