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
Why do we need tuples?
How python supports encapsulation with respect to functions?
Why is used in python?
What is the length of your largest python code? Can you please describe the project?
What is difference between list and set in python?
How will you get a titlecased version of string?
How do you sort in python?
How is python an interpreted language?
Explain how to delete a file in Python?
Define the usage of split?
Explain in detail – inheritance in python?
Write a program in python to produce star triangle.
What happens when a function doesn’t have a return statement? Is this valid?
What are membership?
How to convert a number to a string?