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 orm in python?

0 Answers  


What is python metaclass?

0 Answers  


What is the function of gil in python?

0 Answers  


How to use of return keywords in python?

0 Answers  


What are the benefits of using python?

0 Answers  






How will you merge two dictionaries in python?

0 Answers  


Point out some of the key features of python?

0 Answers  


What is pandas udf?

0 Answers  


What does __ file __ mean?

0 Answers  


Should I use single or double quotes in python?

0 Answers  


1) How to validate ip address using regex 2)program to increment ip address in python Please find answers to above questions thanks in advance.

0 Answers  


Is true a keyword in python?

0 Answers  


Categories