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