ProgrammingHardTCS CodeVita · GATE CS · Advanced

What does the following Python 3 code print? while False: print("never") else: print("while-else")

  1. A. never while-else
  2. B. (nothing printed)
  3. C. while-else
  4. D. never

Correct answer: C. while-else

A while loop's else runs whenever the loop finishes without break, including when the body never executes at all.

More Python Programming questions

Exams that ask this topic