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(x):
    return x * 2
g = f
del f
print(g(3), g.__name__)
try:
    f(1)
except NameError:
    print("gone")
  1. A. 6 g / gone
  2. B. 6 f / gone
  3. C. NameError
  4. D. 6 f / 2

Correct answer: B. 6 f / gone

del removes only the name f; the function object survives because g still refers to it, and it keeps its original __name__.

More Python Programming questions

Exams that ask this topic