Question:

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='*')

Show Hint

f1 prints 3- and returns None, and sep has no effect when print has a single argument.
Updated On: Oct 20, 2026
  • 3-2
  • 3-2*
  • 3-None
  • 3*None-
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: Read the function:
f1(a, b=1) prints a + b and then a hyphen, because end='-' replaces the usual new line. It has no return statement.
So the function returns None.

Step 2: Trace the call c = f1(1,2):
The values are a = 1 and b = 2. The default b = 1 is ignored.
The function prints 3 and then '-', so the screen shows 3- with no new line.
The function returns None, so c = None.

Step 3: Trace print(c, sep='*'):
Here print() gets only one item, c. The sep text goes between items, so with one item it is never used.
It prints None and then a new line.

Step 4: Join the two outputs:
The first print gave '3-' and the second gave 'None', both on the same line. The full output is 3-None.

Step 5: Why the other options are wrong:
(A) 3-2 treats b as the return value. (B) 3-2* uses sep wrongly. (D) 3*None- puts sep and the hyphen in the wrong place.

Final Answer:
The output is 3-None, option (C).
Was this answer helpful?
0
0

Top CBSE CLASS XII Functions Questions