What is the difference between default parameters and positional parameters in Python ? Also give an example of a function header which uses both.
What is the difference between default parameters and positional parameters in Python ? Also give an example of a function header which uses both.
Positional parameters are matched to arguments strictly by their position/order in the function call and must always be supplied by the caller, whereas default parameters are assigned a default value in the function header and become optional — if the caller omits them, the default value is used.
Example function header using both:
``python
def calculate_bill(item, qty, discount=10):
...
`
Here, item and qty are positional parameters (compulsory, matched by order), while discount` is a default parameter (optional, defaults to 10 if not passed).
Marking Scheme
- 11 mark for correctly distinguishing positional parameters (compulsory, order-based) from default parameters (optional, pre-assigned value).
- 21 mark for a syntactically valid function header example containing at least one positional and one default parameter, with defaults placed after positional parameters.
Hint
Positional = compulsory, matched by order; Default = optional, has a fallback value — and defaults must come last in the header.
Quick Oral Answer
Positional parameters must be supplied in order and have no default, while default parameters have a pre-assigned value in the header and can be skipped by the caller; defaults must always come after positional parameters.
Analysis & Explanation
This question checks conceptual clarity on Python's parameter-passing mechanisms, which is foundational to writing flexible functions.
Key distinction
- Positional parameters have no default value; the caller MUST supply a value for each, and values are assigned strictly in the order the arguments appear.
- Default parameters carry a default value specified in the function header (using
=); the caller MAY omit the corresponding argument, in which case Python uses the default.
Rule students often miss
- In a function header, ALL default parameters must appear AFTER all positional parameters —
def f(a=1, b):is aSyntaxErrorbecause a non-default parameter cannot follow a default one.
Common Mistakes
- 1Writing a function header with a default parameter before a positional parameter, e.g. `def f(a=1, b):`, which is a SyntaxError.
- 2Confusing 'default parameters' with 'keyword arguments' passed at the call site — the default value is defined in the function's header, not at the call.
Interesting Facts
Python evaluates default parameter values only ONCE, at the time the function is defined — a classic pitfall occurs when a mutable default (like a list) is modified across multiple calls, retaining state unexpectedly.
Python also supports keyword-only parameters (placed after a `*` in the header), which must always be passed by name, offering a third parameter-passing style beyond positional and default.
Spotted a mistake or something unclear?
Tell us — we fix reported answers fast.
Frequently Asked Questions
Can a positional parameter appear after a default parameter in a function header?
No, this raises a SyntaxError. All positional (non-default) parameters must be listed before any default parameters in the function header.
Can a default parameter be overridden when calling the function?
Yes. If the caller explicitly passes a value for that parameter, it overrides the default; only if the argument is omitted does Python use the default value.