Learn Python like a Professional! Take You from 0 to Hero
In this Python lecture, we will learn about the Error & Exception(try, except & finally).
Let's see some example-
"When Python encounters error while running the code, it stops execution and raises an exception".
Let's see some example-
Error & Exception
1/0
1 + 'string'
if 2<3 print('Hi')
Try, except,else & finally
def division(a,b):
try:
result=a/b
except Exception:
print("Sorry! Division is not possible")
else:
print("sum of a and b =",result)
division(1,0)
def division(a,b):
try:
result=a/b
except Exception as e:
print(e)
else:
print("sum of a and b =",result)
division(1,0)
def division(a,b):
try:
result=a/b
except Exception as e:
print(e)
else:
print("sum of a and b =",result)
division(1,'string')
def division(a,b):
try:
result=a/b
except Exception as e:
print(e)
else:
print("sum of a and b =",result)
division(1,2)
def division(a,b):
try:
result=a/b
except Exception as e:
print(e)
else:
print("sum of a and b =",result)
finally:
print("Executing finally block.....")
division(1,2)
Executing finally block.....
division(1,0)
Executing finally block.....
EDITS ARE WELCOMED!!
In the next Blog, we will discuss Q&A 5th
https://sngurukuls247.blogspot.com/2018/12/python-ninja-bootcamp-30-q-5th.html
......................................................................................................................................
Instagram
https://www.instagram.com/python.india/
View the Jupyter Notebook for this lecture
Download the Jupyter Notebook for this lecture
https://sngurukuls247.blogspot.com/2018/12/python-ninja-bootcamp-30-q-5th.html
......................................................................................................................................
Follow the link below to access Free Python Lectures-
https://www.youtube.com/channel/UCENc9qI7_r8KMf6-_1R1xnwhttps://www.instagram.com/python.india/
View the Jupyter Notebook for this lecture
Feel free contact me on-
Email - sn.gurukul24.7uk@gmail.com
No comments:
Post a Comment