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

How is unit test done in python?

0 Answers  


How would you randomize the contents of a list in-place?

0 Answers  


List out standard datatypes in python

0 Answers  


What is format () in python?

0 Answers  


Write a program to find the duplicates in a list?

0 Answers  






How to make a chain of function decorators?

0 Answers  


What is python namespace?

0 Answers  


Is python better than matlab?

0 Answers  


How do I convert a number to a string?

0 Answers  


What is tuple in python?

0 Answers  


What is class super?

0 Answers  


What are cookies python?

0 Answers  


Categories