How can you create an else block that executes after a for loop, but only if the loop completed normally (i.e., did not encounter a break statement)?

  • Place the code after the "for" loop without any specific block.
  • Use the "except" block
  • Use the "finally" block
  • You cannot create an "else" block for this purpose in Python.

In Python, you can create an "else" block that executes after a for loop but only if the loop completed normally (without encountering a "break" statement). To do this, you can use the "else" block immediately following the "for" loop. If the loop completes normally, the "else" block will execute.

Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *