Computer Science
What is the utility of : (i) default arguments, (ii) keyword arguments ?
Python Functions
17 Likes
Answer
(i) Default arguments — Default arguments are useful in case a matching argument is not passed in the function call statement. They give flexibility to specify the default value for a parameter so that it can be skipped in the function call, if needed. However, still we cannot change the order of the arguments in the function call.
(ii) Keyword arguments — Keyword arguments are useful when you want to specify arguments by their parameter names during a function call. This allows us to pass arguments in any order, as long as we specify the parameter names when calling the function. It also makes the function call more readable and self-explanatory.
Answered By
7 Likes
Related Questions
What do you understand by flow of execution ?
What are arguments ? What are parameters ? How are these two terms different yet related ? Give example.
Explain with a code example the usage of default arguments and keyword arguments.
Describe the different styles of functions in Python using appropriate examples.