Reputation: 747
Is it possible to unpack parameters in python like in javascript?
def foo([ arg ]):
pass
foo([ 42 ])
Upvotes: 3
Views: 2370
Reputation: 61063
Parameter unpacking was removed in Python 3 because it was confusing. In Python 2 you can do
def foo(arg, (arg2, arg3)):
pass
foo( 32, [ 44, 55 ] )
The equivalent code in Python 3 would be either
def foo(arg, arg2, arg3):
pass
foo( 32, *[ 44, 55 ] )
or
def foo(arg, args):
arg2, arg3 = args
foo( 32, [ 44, 55 ] )
Upvotes: 3