What will be the output of the following code ?
``python
def f1(a,b=1):
print(a+b,end='-')
c=f1(1,2)
print(c,sep='*')
``
What will be the output of the following code ?
``python
def f1(a,b=1):
print(a+b,end='-')
c=f1(1,2)
print(c,sep='*')
``
Options
Correct option: (C) 3-None
b takes the passed value 2 (overriding the default), so a+b=3 is printed with end='-' (no newline); since f1 has no return statement, c becomes None, and print(c, sep='*') simply prints None (sep is irrelevant with a single argument).
Marking Scheme
- 11 mark: correct option (C) 3-None selected; no partial credit awarded for MCQ.
Hint
Trace what f1() actually prints AND what it returns — a function with no return statement always returns None.
Quick Oral Answer
f1(1,2) prints '3-' because b is overridden to 2, but since f1 has no return statement it returns None, so print(c) displays 'None', giving overall output 3-None.
Analysis & Explanation
Tracing this program requires tracking both the printed output and the function's return value.
Why (C) is correct
- The call
f1(1,2)passesb=2positionally, overriding the defaultb=1, soa+b = 1+2 = 3. print(a+b, end='-')prints3-without moving to a new line becauseendreplaces the default\n.f1has noreturnstatement, so Python implicitly returnsNone; thereforec = None.print(c, sep='*')prints a single value,None; thesepargument only affects spacing between multiple arguments toprint(), so it has no visible effect here.- Combining both
print()calls gives the final displayed text3-None.
Why the other options are wrong
- (A)
3-2wrongly assumes the function returnsb(or the printed sum) instead ofNone. - (B)
3-2incorrectly appliessep=''as if it inserts a*after a returned value of2. - (D)
3*None-reverses the order of the two print statements and misapplies bothendandsep.
Common Mistakes
- 1Assuming a function without an explicit return statement returns the last computed/printed value instead of None.
- 2Confusing the end parameter (used inside f1's print) with the sep parameter (used in the outer print), leading to wrong option selection.
- 3Forgetting that b=2 overrides the default value b=1 since it is passed positionally.
Interesting Facts
Every Python function implicitly returns None if it reaches the end of its body without an explicit return statement — this is a very common CBSE trap in output-based questions.
The end and sep keyword arguments of print() were introduced in Python 3 to give programmers explicit control over output formatting, replacing Python 2's print statement behaviour.
Spotted a mistake or something unclear?
Tell us — we fix reported answers fast.
Frequently Asked Questions
Why does the function return None even though it prints a value?
Printing and returning are different operations in Python. print() only displays output; a function's return value is whatever follows its return statement. Since f1 has no return statement, Python automatically returns None when the function finishes executing, regardless of what was printed inside it.
Does passing b=2 override the default parameter value b=1?
Yes. Default parameter values are only used when the caller does not supply a value for that argument. Since f1(1,2) supplies two positional arguments, 2 is assigned to b, completely overriding the default of 1 for this call.