【问题标题】:Destruct Python List as Function Arguments [duplicate]将 Python 列表破坏为函数参数 [重复]
【发布时间】:2019-09-23 08:56:54
【问题描述】:

如何像在 javascript 中一样将数组解构为参数列表?

def foo( arg0, arg1 ): pass
bar = [ 32, 44 ]
foo( ...bar )

【问题讨论】:

    标签: python arrays function arguments


    【解决方案1】:

    这称为参数解包。使用*args 格式

    foo(*bar)
    

    更多信息:https://www.geeksforgeeks.org/packing-and-unpacking-arguments-in-python/

    【讨论】:

      猜你喜欢
      • 2015-06-06
      • 2015-10-07
      • 2011-03-31
      • 2011-12-06
      • 2010-11-21
      • 1970-01-01
      • 2017-02-10
      • 1970-01-01
      • 2019-07-23
      相关资源
      最近更新 更多