Test Index
CBSE Class 12 Computer Science 2026 Paper Compartment
© examsnet.com
Question : 23 of 37
Marks:
+1,
-0
What are default parameters in Python functions ? Explain with the help of an example.
Solution:
Default parameters:A default parameter is a parameter that is given a default value in the function header (
parameter=value). If the function is called without an argument for it, the default value is used; if an argument is passed, it replaces the default.Default parameters must come after all non-default parameters in the header, e.g. def f(a, b=5): is valid but def f(a=5, b): is a SyntaxError.Example:def greet(name, msg="Good morning"): print(msg + ",", name)greet("Anu") # msg takes default valuegreet("Ravi", "Hello") # default replaced by "Hello"Output:Good morning, AnuHello, RaviIn the first call only
name is passed, so msg takes its default value "Good morning". In the second call the passed value "Hello" overrides the default.© examsnet.com
Go to Question: