是否可以像在 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 ] )
关于python - 如何在 Python 中解压参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56013914/