ProgrammingHardGATE CS · Product-company placement

What is printed? (Output lines are shown separated by " / ".)

What is printed? (Output lines are shown separated by " / ".)
def f(*, a, b=2):
    return a - b
def g(a, b=2, /):
    return a - b
print(f(b=1, a=5), g(5, 1))
for call in (lambda: f(5), lambda: g(a=5)):
    try:
        call()
    except TypeError:
        print("TE", end=" ")
  1. A. 4 4 / TE TE
  2. B. 4 4 / TE
  3. C. 4 4
  4. D. SyntaxError

Correct answer: A. 4 4 / TE TE

f takes only keyword arguments (after *), so f(5) fails; g takes only positional arguments (before /), so g(a=5) fails. Keyword order in a call does not matter, and both signatures are valid syntax.

More Python Programming questions

Exams that ask this topic