Exceptions
You have already seen exceptions in previous code.They occur when something goes wrong,due to incorrect code or input.When an exception occurs,the program immediately stops.
The following code produces the ZeroDivisionError exception by trying to divide 7 by o.
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 num1=7 4 num2=0 5 print(num1/num2)
result:
1 Traceback (most recent call last): 2 File "./1.py", line 5, in <module> 3 print(num1/num2) 4 ZeroDivisionError: integer division or modulo by zero