Test Index
CBSE Class 12 Computer Science 2026 Paper Set 4
© examsnet.com
Question : 22 of 37
Marks:
+1,
-0
What is the difference between default parameters and positional parameters in Python ? Also give an example of a function header which uses both.
Solution:
Difference:
Example (function header using both):
| Default parameters | Positional parameters |
|---|---|
Given a default value in the function header, e.g. rate=5. | Have no value in the header; they are just names, e.g. p. |
| The argument for it may be left out in the call; then the default value is used. | An argument must be passed for each of them in the call (else TypeError). |
| Must be written after all positional (non-default) parameters in the header. | Get their values by position: the 1st argument goes to the 1st parameter, and so on. |
def interest(p, t, rate=5): # p, t: positional; rate: default return p * t * rate / 100print(interest(1000, 2)) # rate takes default 5 -> 100.0print(interest(1000, 2, 10)) # rate = 10 -> 200.0Key point: A header such as
def interest(rate=5, p, t): is a SyntaxError, because a non-default parameter cannot follow a default parameter.© examsnet.com
Go to Question: