How to Define a Block of Code in Python


In this example we will show how to define a block of code to be executed if no errors were raised using the else keyword in Python.

Source Code

try:
    x = int(10.25)
except:
    print('An exception occurred!')
else:
    print('No errors occurred!')

Output:

No errors occurred!
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments