How can we pass optional or keyword parameters from one function to another in Python?



How can we pass optional or keyword parameters from one function to another in Python?..

Answer / chaitanya

Gather the arguments using the * and ** specifiers in the function's parameter list. This gives us positional arguments as a tuple and the keyword arguments as a dictionary. Then we can pass these arguments while calling another function by using * and **:

def fun1(a, *tup, **keywordArg):

...

keywordArg['width']='23.3c'

...

Fun2(a, *tup, **keywordArg)

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

What does none mean in python?

1 Answers  


how do I protect python code?

1 Answers  


What is python's slice notation?

1 Answers  


Is python easy to learn if you know c++?

1 Answers  


Do you know what is the key difference between a list and the tuple?

1 Answers  


Tell me is there a switch or case statement in python?

1 Answers  


How many keywords are there in python? And why should we know them?

1 Answers  


How are arguments passed by value or by reference?

1 Answers  


does recursion cause any trouble?

1 Answers  


Explain what is namespace in python?

1 Answers  


How the memory is managed in python?

1 Answers  


Can we use break in if statement in python?

1 Answers  


Categories