0

i have a code something like this:

a=1.
b=2.

c=(a,b)

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

test(c,5)

However, it says that there is a syntax error in second paranthesis of: def test((a,b),c)

Any suggestions? (btw this works fine for 2.6.1, i have 3.3.2, i could not find any syntax change regarding this)

alko
  • 46,136
  • 12
  • 94
  • 102
nicomedian
  • 53
  • 1
  • 7

2 Answers2

4

That feature -- tuple parameter unpacking -- was removed from Python 3: http://www.python.org/dev/peps/pep-3113/

You should rewrite your code:

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

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

or

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

test(c, 5) 
1st1
  • 1,101
  • 8
  • 8
1

From What’s New In Python 3.0:

Tuple parameter unpacking removed. You can no longer write def foo(a, (b, c)): .... Use def foo(a, b_c): b, c = b_c instead.

Related PEP: PEP 3113

Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504