ProgrammingHardInfosys HackWithInfy · TCS CodeVita

What does the following Python 3 code print? def f(): for i in range(3): pass else: print("else-ran") f()

  1. A. else-ran
  2. B. None
  3. C. (nothing printed)
  4. D. 0 1 2 else-ran

Correct answer: A. else-ran

The loop runs to completion without a break, so its else clause executes, printing 'else-ran'.

More Python Programming questions

Exams that ask this topic