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 |
Explain the dictionary in Python.
How would you define a block in python?
Which is the invalid variable assignment from the below?
What is loop in python?
What are decorators in python and how do you use them?
What are mixins in python?
How are data types defined in python?
What is deep copy in python?
How many kinds of sequences are supported by python? What are they?
Is python good for web development?
What is used to represent Strings in Python? Is double quotes used for String representation or single quotes used for String representation in Python?
What is the significance of ‘self' parameter in an object method? Should we always name this parameter as ‘self'?