Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
3 views
in Python by (2.6k points)
edited by

What * and ** do for param2 in the following:

def foo(param1, *param2):
def bar(param1, **param2):

2 Answers

0 votes
by (2k points)

The * will give tuple for all the functions parameters whereas ** performs all keyword arguments except some which are formal parameters in dictionary. 

See following commands for Ref.

*arg:

def f(*args):

             for arg in args:

                  print(arg)

f(2,3)

**kwargs

def f(q,w)

     return q+w

def g(**kwargs)

   return f(**kwargs)

g(q=2, w=3)

Doubts are welcomed in comments, Happy Learning.

0 votes
by (106k points)

* and ** have special usage in the function argument list. * implies that the argument is a list and ** implies that an argument is a dictionary. This allows functions to take an arbitrary number of arguments

You can use the following video tutorials to clear all your doubts:-

Related questions

Browse Categories

...