Question:

What is the difference between default parameters and positional parameters in Python? Also give an example of a function header which uses both.

Show Hint

A positional parameter must always be passed. A default parameter has a value in the header and can be skipped. Example: def calc(a, b=10).
Updated On: Oct 20, 2026
Show Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Positional parameters:
A positional parameter has no value in the function header, so the caller must pass a value for it.
The values are matched with the parameters by their position, left to right.
If the caller leaves one out, Python raises a TypeError.

Step 2: Default parameters:
A default parameter is given a value in the header with the = sign.
If the caller does not pass that argument, Python uses the default value.
If the caller passes a value, the default is replaced for that call.
Default parameters must come after all positional parameters in the header.

Step 3: Example of a header that uses both:
def calc(a, b=10, c=20):
    return a + b + c
Here a is positional. The parameters b and c are default parameters.
calc(1) gives 31, because b=10 and c=20 are used.
calc(1, 2) gives 23, because b becomes 2 and c stays 20.
calc(1, c=5) gives 16, because b stays 10 and c becomes 5.

Final Answer:
Positional parameters must be supplied by the caller and are matched by order. Default parameters carry a preset value that is used when the argument is missing.
Example header: def calc(a, b=10, c=20):
Was this answer helpful?
0
0

Top CBSE CLASS XII Functions Questions