try with finally block in python by R4R Team

Try-
-Try block is a block in which we write that part of program where chances of exception will occur.
Finally-
It is part which will always run if exception will occur or not.

Syntax-

try
block
finally:
block:


program-

try:
n=1/int(input("Enter numbern"))
print(n)
except:
print("Number is divided by zero")
finally :
print("After try block")


output-

Enter number
1
1.0
After try block

Enter number
0
Number is divided by zero
After try block


-In this program and output, we can see that finially block is always run if exception will occur or not




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!