Vidyalelo
Python · all questions

Exception Handling in Python
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

65

Questions

2/4

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following Python code?
def f(x):
    yield x+1
    print("test")
    yield x+2
g=f(9)

Select an option to see the answer and solution.

What happens when '1' == 1 is executed?

Select an option to see the answer and solution.

Which of the following is not a standard exception in Python?

Select an option to see the answer and solution.

Is the following Python code valid?
try:
    # Do something
except:
    # Do something
finally:
    # Do something

Select an option to see the answer and solution.

What is the purpose of the except clause without specifying an exception type in a try block?

Select an option to see the answer and solution.

What is the purpose of the else clause in a try block?

Select an option to see the answer and solution.

Identify the type of error in the following Python codes?
Print(“Good Morning”)
print(“Good night)

Select an option to see the answer and solution.

Which of the following is not a standard Python exception?

Select an option to see the answer and solution.

What is the purpose of the sys.exc_info() function in Python?

Select an option to see the answer and solution.

What will be the output of the following Python code?
g = (i for i in range(5))
type(g)

Select an option to see the answer and solution.

How can you catch and handle multiple exceptions in a single except block in Python?

Select an option to see the answer and solution.

What is the output of the following code:
try:
x = 10 / 0
except ZeroDivisionError:
print("Error!")
finally:
print("Finally!")

Select an option to see the answer and solution.

What will be the output of the following Python code?
def foo():
    try:
        print(1)
    finally:
        print(2)
foo()

Select an option to see the answer and solution.

What will be the output of the following Python code?
int('65.43')

Select an option to see the answer and solution.

How can you catch and handle multiple exceptions in a single except block in Python?

Select an option to see the answer and solution.

What is the syntax to raise an exception manually in Python?

Select an option to see the answer and solution.

An exception is . . . . . . . .

Select an option to see the answer and solution.

What will be the output of the following Python code?
def f(x):
    yield x+1
    print("test")
    yield x+2
g=f(10)
print(next(g))
print(next(g))

Select an option to see the answer and solution.

Which of the following statements is true regarding the order of except clauses?

Select an option to see the answer and solution.

Compare the following two Python codes shown below and state the output if the input entered in each case is -6?
CODE 1
import math
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))
 
CODE 2
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))

Select an option to see the answer and solution.