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 |
What is python? What do you understand of pep 8?
Explain between deep and shallow copy?
What is string parsing in python?
What are the runtime errors?
What are python variables?
How would you randomize the contents of a list in-place?
How can you keep track of different versions of code?
What is difference between match & search in regex module in python?
Do you always need a default constructor?
Mention the rules for local and global variables in python?
What is hierarchical inheritance?
Why does comparing strings in python using either ‘==’ or ‘is’ sometimes produce a different result?