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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

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

501


Explain the Meaning of a single and double underscore before an object name?

493


How many variables are in python?

451


What is python keyword?

471


As python is more suitable for the server-side application, it is very important to have threading implemented in your server code. How can you achieve that in python?

458






What is Python Decorator?

527


What does the enum function in python do?

467


What applications use python?

422


Differentiate list and tuple with an example?

448


What is Dict and List comprehensions are?

553


What is type () in python?

499


Is python a good first language?

431


How to get the current time in python?

453


Tell me what are generators in python?

454


How do you create a list which is a reverse version on another list in python?

468