Using the try-except-else block

PHOTO EMBED

Mon Mar 08 2021 22:28:43 GMT+0000 (Coordinated Universal Time)

Saved by @randomize_first #python

a, b = 1,0

try:
    print(a/b)
    # exception raised when b is 0
except ZeroDivisionError:
    print("division by zero")
else:
    print("no exceptions raised")
finally:
    print("Run this always")
view raw
content_copyCOPY