是否可以像javascript一样在python中解压缩参数?
def foo([ arg ]):
pass
foo([ 42 ])
答案 0 :(得分:1)
参数解压缩为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 ] )