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 happens if an error occurs that is not handled in the except block?

0 Answers  


Does python have static classes?

0 Answers  


Which server is used for python?

0 Answers  


Tell us what is module and package in python?

0 Answers  


Write one line of code to get a list of names that start with character ‘j’?

0 Answers  


Whats the difference between input() and raw_input()?

0 Answers  


Why was the language called as Python?

0 Answers  


What is flask used for in python?

0 Answers  


So, what is an iterator, then?

0 Answers  


What is "typeerror: 'module' object is not callable"?

0 Answers  


What are the attributes?

0 Answers  


Is python a pop or oop?

0 Answers  


Categories