Question 1 of 25
Hints left: 3
Q1
What is the purpose of the assert statement in Python?
Q2
What will be the output of the following Python code? class A: def one(self): return self.two() def two(self): return 'A' class B(A): def two(self): return 'B' obj2=B() print(obj2.two())
Q3
Can one block of except statements handle multiple exception?
Q4
Which built-in Python function can be used to retrieve the error message associated with an exception?
Q5
Which of the following statements is true regarding the order of except clauses?
Q6
What will be the output of the following Python code? class Demo: def __init__(self): self.a = 1 self.__b = 1 def display(self): return self.__b obj = Demo() print(obj.__b)
Q7
How many except statements can a try-except block have?
Q8
When is the finally block executed?
Q9
What will be the output of the following Python code? class A: def __init__(self): self.__i = 1 self.j = 5 def display(self): print(self.__i, self.j) class B(A): def __init__(self): super().__init__() self.__i = 2 self.j = 7 c = B() c.display()
Q10
What will be the output of the following Python code? class student: def __init__(self): self.marks = 97 self.__cgpa = 8.7 def display(self): print(self.marks) obj=student() print(obj._student__cgpa)
Q11
When will the else part of try-except-else be executed?
Q12
What is the benefit of using polymorphism in object-oriented programming?
Q13
What will be the output of the following Python code? class A: def test1(self): print(" test of A called ") class B(A): def test(self): print(" test of B called ") class C(A): def test(self): print(" test of C called ") class D(B,C): def test2(self): print(" test of D called ") obj=D() obj.test()
Q14
What is the output of the following code: try: x = 10 / 0 except ZeroDivisionError: print("Error!") finally: print("Finally!")
Q15
Overriding means changing behaviour of methods of derived class methods in the base class.
Q16
What is the purpose of the except clause in a try block?
Q17
What type of inheritance is illustrated in the following Python code? class A(): pass class B(A): pass class C(B): pass
Q18
How is the concept of abstraction achieved in object-oriented programming?
Q19
What is an exception in Python?
Q20
What will be the output of the following Python code? class A: def __repr__(self): return "1" class B(A): def __repr__(self): return "2" class C(B): def __repr__(self): return "3" o1 = A() o2 = B() o3 = C() print(obj1, obj2, obj3)
Q21
What will be the output of the following Python code? class Demo: def check(self): return " Demo's check " def display(self): print(self.check()) class Demo_Derived(Demo): def check(self): return " Derived's check " Demo().display() Demo_Derived().display()
Q22
What will happen if an exception is raised in a try block and is not handled in any of the except blocks?
Q23
The following Python code will result in an error if the input value is entered as -5. assert False, 'Spanish'
Q24
Which keyword is used to handle exceptions in Python?
Q25
What is the purpose of exception handling in Python?