Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (55.6k points)

Can anyone tell me how to handle multiple exceptions in Python?

1 Answer

0 votes
by (119k points)

One try block can have multiple except blocks and here is an example of using two except blocks for handling two different exception types:

try:

    a=5

    b=0

    print (a/b)

except TypeError:

    print('Unsupported operation')

except ZeroDivisionError:

    print ('Division by zero not allowed')

print ('Out of try except blocks')

Output:

Division by zero not allowed

Out of try except blocks

I recommend enrolling in this Python Training Course by Intelllipaat to learn Python.

You can watch this Exception Handling in Python:

Browse Categories

...