Exception Handling
1.
How many except statements can a try-except block have?
2.
When will the else part of try-except-else be executed?
3.
Is the following Python code valid?
try:
# Do something
except:
# Do something
finally:
# Do something
4.
Is the following Python code valid?
try:
# Do something
except:
# Do something
else:
# Do something
5.
Can one block of except statements handle multiple exception?
6.
When is the finally block executed?
7.
What will be the output of the following Python code?
def foo():
try:
return 1
finally:
return 2
k = foo()
print(k)
8.
What will be the output of the following Python code?
def foo():
try:
print(1)
finally:
print(2)
foo()
9.
What will be the output of the following Python code?
try:
if '1' != 1:
raise "someError"
else:
print("someError has not occurred")
except "someError":
print ("someError has occurred")
10.
What happens when ‘1’ == 1 is executed?