python 3.3.2函数定义多参数语法

时间:2013-11-21 21:39:14

标签: python python-3.x syntax

我有一个像这样的代码:

a=1.
b=2.

c=(a,b)

def test((a,b),c):
    return a+b+c

test(c,5)

但是,它表示在第二个例子中存在语法错误:def test((a,b),c)

有什么建议吗? (顺便说一句这适用于2.6.1,我有3.3.2,我找不到任何关于此的语法更改)

2 个答案:

答案 0 :(得分:4)

该功能 - 元组参数解包 - 已从Python 3中删除:http://www.python.org/dev/peps/pep-3113/

您应该重写代码:

def test(a, b, c):
    return a + b + c

test(c[0], c[1], 5)

def test(a, b):
    return a[0] + a[1] + b

test(c, 5) 

答案 1 :(得分:1)

来自What’s New In Python 3.0

  

删除了元组参数解包。您无法再写def foo(a, (b, c)): ....而是使用def foo(a, b_c): b, c = b_c

相关PEP:PEP 3113