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 |
When do you use list vs. tuple vs. dictionary vs. set?
where can I get the study material for python
Name the function which helps to change the files permission
How do you represent binary and hexadecimal numbers?
Who built the sphinx?
Describe python usage in web programming?
Does flask work with python 3?
What are python and name some key features of it?
Explain how to make Forms in python.
What is the difference between `del` and `remove()` in Python?
What is itemgetter in python?
Why do we need the __init__() function in classes? What else helps?