Back

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

Can anyone tell me how exceptions are handled in Python?

1 Answer

0 votes
by (119k points)
edited by

In Python, exceptions are handled using a try statement. The critical operation that may encounter exception will be placed inside the try clause. The code that handles the exceptions that are caught in try block will be written in except block. Here is a simple example:

try:

    a=5

    b='0'

    print(a/b)

except:

    print('Some error occurred.')

print("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:

Related questions

0 votes
1 answer
asked Oct 30, 2020 in Python by Sudhir_1997 (55.6k points)
0 votes
1 answer

Browse Categories

...