ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
def f():
    for i in range(3):
        try:
            return i
        finally:
            if i == 0:
                continue
print(f())
  1. A. 0
  2. B. 2
  3. C. None
  4. D. 1

Correct answer: D. 1

Since Python 3.8, continue is allowed in finally; it discards the pending return 0 and the loop goes on. On i = 1 the finally does nothing, so return 1 completes.

More Python Programming questions

Exams that ask this topic