Source: levelup.gitconnected.com

4 ‘Else Clauses’ in Python
In Python, we might find else clause in if statement, for, while loops, and try block also. else clause is optional in all these statements.

The try statement specifies exception handlers and/or cleanup code for a group of statements: Syntax:try:In the try block, code is executed and if an exception is raised, control goes to the except clause.

else:else clause is executed if the control flow leaves the try suite, no exception was raised, and no return, continue, or break statement was executed.

Even when a return, break or continue statement is executed in the try suite of a try…

Related Articles