Describe how exceptions are handled in python.



Describe how exceptions are handled in python...

Answer / chaitanya

Errors detected during execution of program are called exceptions. Exceptions can be handled using the try..except statement. We basically put our usual statements within the try-block and put all our error handlers in the except-block.

try…except demo code:

>>> while True:

try:

x = int(raw_input("Enter no. of your choice: "))

break

except ValueError:

print "Oops! Not a valid number. Attempt again"

Enter no. of your choice: 12ww

Oops! Not a valid number. Attempt again

Enter no. of your choice: hi there

Oops! Not a valid number. Attempt again

Enter no. of your choice: 22

>>>

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

When do you use list vs. tuple vs. dictionary vs. set?

1 Answers  


where can I get the study material for python

1 Answers  


Name the function which helps to change the files permission

1 Answers  


How do you represent binary and hexadecimal numbers?

1 Answers  


Who built the sphinx?

1 Answers  


Describe python usage in web programming?

1 Answers  


Does flask work with python 3?

1 Answers  


What are python and name some key features of it?

1 Answers  


Explain how to make Forms in python.

1 Answers  


What is the difference between `del` and `remove()` in Python?

1 Answers  


What is itemgetter in python?

1 Answers  


Why do we need the __init__() function in classes? What else helps?

1 Answers  


Categories