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 |
Which data type you prefer to implement when deal with seuential data?
Differentiate between range and xrange.
How type casting is done in python?
Explain about exceptions in python?
Should I learn python before c?
What are the optional statements that can be used inside a <try-except> block in python?
What is python identifiers?
How to add an index, row or column to a pandas dataframe?
How can you copy an object in Python?
What is tuple in python?
What is the purpose of #!/usr/bin/pythonon the first line in the above code? Is there any advantage?
Explain me database connection in python flask?