Passing list and dictionary type parameter with Python

Posted by prosseek on Stack Overflow See other posts from Stack Overflow or by prosseek
Published on 2010-04-26T18:09:55Z Indexed on 2010/04/26 18:23 UTC
Read the original article Hit count: 350

Filed under:
|

When I run this code

def func(x, y, *w, **z):
  print x
  print y
  if w:
      print w

  if z:
      print z
  else:
      print "None"

func(10,20, 1,2,3,{'k':'a'})

I get the result as follows.

10
20
(1, 2, 3, {'k': 'a'})
None

But, I expected as follows, I mean the list parameters (1,2,3) matching *w, and dictionary matching **z.

10
20
(1,2,3)
{'k':'a'}

Q : What went wrong? How can I pass the list and dictionary as parameters?

Added

func(10,20, 10,20,30, k='a')

seems to be working

© Stack Overflow or respective owner

Related posts about python

Related posts about parameter-passing