Question:medium

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

Solution and Explanation

Step 1: Compare the two in the function call:
Take the call calc(1). Only one argument is sent.
The parameter a has no preset value, so it takes the 1 that was sent. This is a positional parameter.
The parameters b and c have preset values in the header, so Python fills them itself. These are default parameters.

Step 2: State the difference:
A positional parameter is compulsory. Leaving it out gives a TypeError.
A default parameter is optional. Leaving it out is safe, because its default value is used.
In the header, every default parameter must sit after the positional ones. A header such as def f(a=1, b): is a syntax error.

Step 3: Show the header and check it:
def calc(a, b=10, c=20):
    return a + b + c

print(calc(1))
print(calc(1, 2))
print(calc(1, c=5))
Output of the three print lines: 31, 23 and 16.
The first value goes to a every time. This shows a is positional and b, c are default.

Final Answer:
Positional parameter: no preset value, must be passed, matched by order. Default parameter: has a preset value, may be left out.
Header using both: def calc(a, b=10, c=20):
Was this answer helpful?
0