Page 6 - LN
P. 6
Lesson Note
Positional Arguments
Default Arguments
Parameter in the function definition may contain default argument.
If no values supplied for a parameter in a function call in that case parameter takes default values.
All valid function call, default argument will work
where ever value not supplied for the parameters.
Python allocates argument values to different parameter from left to right as defined in the
parameter list of the function header.
Default value allocation has to be from right, gradually.
Valid function header:
def SimpleInterest(P, R, T)
def SimpleInterest(P, R, T=5)
def SimpleInterest(P, R=3, T=5)
def SimpleInterest(P=5000, R=3, T=5)
Invalid function header:
def SimpleInterest(P=5000, R=3, T)
def SimpleInterest(P=5000, R, T=5)
def SimpleInterest(P=5000, R, T)
def SimpleInterest(P, R=3, T)
Imp:
Default arguments are considered only if no value is provided for a parameter in the function call
statement.
Keyword Arguments
If there is a function with many parameters and we want to specify only some of them in the
function call, then value of such parameters can be provided by using their name instead of the
position order. These are called keyword arguments.
For a function header: