Correct option is A
In Python, when defining a function with parameters,
default values must be given to the parameters that come after parameters without default values. This rule ensures that Python knows how to assign values to parameters when the function is called.
Let's examine the options:
·
(a) def Compu(X=100, Y=10, Z): - This will result in an error because
Z has no default value but comes after parameters that already have default values (X=100 and Y=10). In Python, all parameters with default values must come
after those without default values.
·
(b) def Compu(X, Y, Z=1): - This is
valid. Z has a default value, but X and Y do not, so the order is correct.
·
(c) def Compu(X=100, Y=10, Z=1): - This is
valid because all parameters (X, Y, and Z) have default values, which is allowed.
·
(d) def Compu(X, Y=10, Z=1): - This is
valid because Y and Z have default values, but X does not. This is a correct way to define the function.
Important Key Points:
1.
Default Parameters: All parameters with default values must be defined after parameters without default values.
2.
Order of Parameters: You cannot specify a default value for a parameter if there are already parameters without default values following it.
Knowledge Booster:
· If you want to give a default value to a parameter, it must be placed at the end of the parameter list.
· Functions can have any number of parameters with default values, as long as they come after parameters that don’t have default values.