Exception-Hadling

Wed 12 November 2025
#  created : 20250111
#  https://www.scientecheasy.com/2022/09/reserved-keywords-in-python.html/
# Python Exception Handling Keywords
x = 10
y = 0

try:
    z = x // y 
    print(z)

except ZeroDivisionError:
    print("Cannot divide by zero")

finally:
    print("finally block always gets executed")
Cannot divide by zero
finally block always gets executed
#  assert Keyword
x = 10 

assert x >= 10 
assert x < 10
---------------------------------------------------------------------------

AssertionError                            Traceback (most recent call last)

Cell In[10], line 4
      1 x = 10 
      3 assert x >= 10 
----> 4 assert x < 10


AssertionError:
x = 10
assert x < 10,"x is not less than 10"
---------------------------------------------------------------------------

AssertionError                            Traceback (most recent call last)

Cell In[13], line 2
      1 x = 10
----> 2 assert x < 10,"x is not less than 10"


AssertionError: x is not less than 10


Score: 5

Category: python-basics