如何解压Python中的参数?

How to unpack parameters in Python?

是否可以像 javascript 那样在 python 中解压参数?

def foo([ arg ]):
    pass

foo([ 42 ])

参数解包是 removed in Python 3,因为它令人困惑。在 Python 2 你可以做

def foo(arg, (arg2, arg3)):
    pass

foo( 32, [ 44, 55 ] )

Python 3 中的等效代码是

def foo(arg, arg2, arg3):
    pass

foo( 32, *[ 44, 55 ] )

def foo(arg, args):
    arg2, arg3 = args

foo( 32, [ 44, 55 ] )