1. Home
  2. Data Science
  3. Python
  4. What does the 'else' statement in a loop signify in Python?

Added 10 Feb 2024

What does the 'else' statement in a loop signify in Python?

  1. It is executed if the loop encounters an error
  2. It indicates the end of the loop
  3. It is executed if the loop completes without encountering a 'break' statement Correct answer
  4. It defines an alternative condition for the loop

Correct answer

C. It is executed if the loop completes without encountering a 'break' statement

17 views

MCQSEXAM

Explanation

In Python loops, the 'else' statement is executed if the loop completes all iterations without encountering a 'break' statement. It is useful for executing code after the loop has completed successfully.

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs