是否可以像在javascript中那样在python中解压缩参数?
def foo([ arg ]): pass foo([ 42 ])
在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 ] )
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
点击生成二维码
我来说两句