ProgrammingModerateTCS NQT · Python

What is printed?

What is printed?
def f():
    try:
        return 'a'
    finally:
        print('f', end=' ')
print(f())
  1. A. f a
  2. B. a f
  3. C. a
  4. D. f

Correct answer: A. f a

The finally block runs before the function actually returns, so 'f ' is printed first and then print outputs the returned 'a'.

More Python Programming questions

Exams that ask this topic