Positional and Keyword Argument in python.
Positional Argument
If there are more then one parameters are present in a function, how does python idenify which argument in the statement has to assign which parameter. The parameter are assign accordings to their position i.e. first argument in the first column.
Example 1:
Output:
Example 2:
Error:
Keyword Argument
An alternative to positional argument is keyword argument. If the program knows the parameter name use within the function then they can use the parameter name by calling the function. This is done by:
Example:
Output:
Precautions of using Keyword argument:
1. A positional argument can not follows keyword argument.
Example 1:
Output
Example 2:
Error:
2. We can not duplicate an argument by specifying it by as both positional and keyword argument.
Example:
Error:
Parameter with Default value:
Parameter within function definition can have default values, we can provide default value to a parameter using assignment operator.
Output:
When we pass the actual value even a default value is define in function, it will overwrite the default value.
Output:
Comments
Post a Comment