What is the purpose of the else clause in a Python loop?
- To define loop initialization
- To execute code after the loop completes without a break
- To handle exceptions
- To specify an alternate loop condition
The else clause in a Python loop is used to execute code after the loop completes without a break statement being encountered.
Loading...
Related Quiz
- Which Python object can be used to create a simple context manager without defining a class?
- The ____ method is used to pre-fetch the next value of a generator object.
- Which keyword allows the creation of a block of code that always runs, regardless of exceptions?
- How would you dynamically import a module if you have the module’s name stored in a string variable?
- What is the base class in Python from which all exceptions inherit?