Advertisement
Advertisement
#Defining a class named Exp and its three functions
class Exp :
#First function of class Exp
def func1(self):
#Using self keyword to call a function from the inside of another function
self.func2()
#Second function of class Exp
def func2(self):
self.func3()
#Third function of class Exp
def func3(self):
print(100/0)
print("Hello from funct3()")
#Creating an object of class Exp
ob = Exp()
#Calling the function method1() of class Exp
ob.func1()
#This statement won't be executed because of an exception rising before the execution of this statement
print("Hello")
Traceback (most recent call last):
File "D:/Python Programs/excp3.py", line 28, in <module>
ob.method1()
File "D:/Python Programs/excp3.py", line 6, in func1
self.method2()
File "D:/Python Programs/excp3.py", line 12, in func2
self.method3()
File "D:/Python Programs/excp3.py", line 18, in func3
print(100/0)
ZeroDivisionError: division by zero
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement