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 do you remove duplicates from a list in python whilst preserving order?

0 Answers  


How to open a text file and display its contents?

0 Answers  


Which of the languages does Python resemble in its class syntax?

0 Answers  


What is final and super keyword difference between them?

0 Answers  


Which database is best for python?

0 Answers  






How do you execute a python script?

0 Answers  


Explain about python’s parameter passing mechanism?

0 Answers  


What is the length of your largest python code? Can you please describe the project?

0 Answers  


Can you sort a string in python?

0 Answers  


What is python slice()?

0 Answers  


What is numpy array in python?

0 Answers  


Is upper in python?

0 Answers  


Categories