Raising Errors in Python
# Raises different types of errors
# syntax error
a = 0
if a == 0
print("Hi")
# name error
print(a)
# type error
print(2+"Hi")
# index error
l = [1,2,3,4,5]
print(l[5])
# atrribute error
l = [1,2,3,4,5]
l.popl()
def add(a,b):
if (type(a) is int) and (type(b) is int):
return a + b
raise TypeError("Wrong data type passed...")
print(add("2","3"))
Post a Comment