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

What is singleton class in python?

0 Answers  


What is the necessity to use pass statement in python program?

0 Answers  


What are basic overloading methods in python?

0 Answers  


What is a Lambda form? Explain about assert statement?

1 Answers  


What are “special” methods in python?

0 Answers  






Does python have a-main() method?

0 Answers  


What is python programming language?

0 Answers  


How do you reload a python module?

0 Answers  


Definition of %s in python?

0 Answers  


How to check the string consists of alphanumeric characters ?

0 Answers  


What does isnull mean in python?

0 Answers  


What is a method call?

0 Answers  


Categories