Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Practice InterviewNew Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Python Interview Questions and Answers

Ques. How can I pass optional or keyword parameters from one function to another?
Ans. Collect the arguments using the * and ** specifier in the function's parameter list; this gives you the positional arguments as a tuple and the keyword arguments as a dictionary. You can then pass these arguments when calling another function by using * and **:
def f(x, *tup, **kwargs):
g(x, *tup, **kwargs)
In the unlikely case that you care about Python versions older than 2.0, use 'apply': def f(x, *tup, **kwargs):
apply(g, (x,)+tup, kwargs)
Is it helpful? Yes No

Most helpful rated by users:

©2019 WithoutBook