Q.What will be the output of the following code ? def f1(a,b=1): print(a+b,end='-') c=f1(1,2) print(c,sep='') (A) 3-2 (B) 3-2 (C) 3-None (D) 3*None-
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →The function f1 prints 3- (since 1+2=3 with end='-'), then returns None implicitly, which the outer print displays — giving 3-None, option (C).
When a Python function has no explicit return, it returns None. This question tests the difference between what a function prints and what it returns, and how print handles None and its keyword arguments.
The function f1(a, b=1) computes a+b and prints it with end='-' instead of a newline. There is no return, so calling f1(1,2) prints the sum and evaluates to None, which is then assigned to c.
Trace of the execution:
-
Call
f1(1, 2)— inside,a=1andb=2, soa+bis3. -
print(a+b, end='-')— outputs3and, instead of a newline, ends with-. So far the console shows:3- -
Function returns
None— with noreturnstatement,f1returnsNone, soc = f1(1,2)storesNoneinc. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.