

MCQOPTIONS
Saved Bookmarks
This section includes 1007 Mcqs, each offering curated multiple-choice questions to sharpen your Technical Programming knowledge and support exam preparation. Choose a topic below to get started.
51. |
Which one of these is floor division |
A. | / |
B. | // |
C. | % |
D. | none |
Answer» C. % | |
52. |
Which of the following blocks will be executed whether an exception is thrown or not? |
A. | except |
B. | else |
C. | finally |
D. | assert |
Answer» D. assert | |
53. |
_______________________ exceptions are raised as a result of an error in opening a particular file. |
A. | ValueError |
B. | TypeError |
C. | ImportError |
D. | IOError |
Answer» E. | |
54. |
An exception is: |
A. | an object |
B. | a special function |
C. | a standard module |
D. | a module |
Answer» B. a special function | |
55. |
Which of the following is not a standard exception in Python? |
A. | NameError |
B. | IOError |
C. | AssignmentError |
D. | ValueError |
Answer» D. ValueError | |
56. |
Identify the type of error in the codes shown below. Print(“Good Morning”) print(“Good night) |
A. | Syntax, Syntax |
B. | Semantic, Syntax |
C. | Semantic, Semantic |
D. | Syntax, Semantic |
Answer» C. Semantic, Semantic | |
57. |
What is the output of the code shown below? def getMonth(m): if m<1 or m>12: raise ValueError("Invalid") print(m) getMonth(6) |
A. | ValueError |
B. | Invalid |
C. | 6 |
D. | ValueError(“Invalid”) |
Answer» D. ValueError(“Invalid”) | |
58. |
The output of the code shown below is: int('65.43') |
A. | ImportError |
B. | ValueError |
C. | TypeError |
D. | NameError |
Answer» C. TypeError | |
59. |
What is the output of the following code, if the time module has already been imported? 4 + '3' |
A. | NameError |
B. | IndexError |
C. | ValueError |
D. | TypeError |
Answer» E. | |
60. |
What is the output of the code shown below? t[5] |
A. | IndexError |
B. | NameError |
C. | TypeError |
D. | ValeError |
Answer» C. TypeError | |
61. |
What is the output of the code shown below? lst = [1, 2, 3] lst[3] |
A. | NameError |
B. | ValueError |
C. | IndexError |
D. | TypeError |
Answer» D. TypeError | |
62. |
What happens if the file is not found in the code shown below? a=False while not a: try: f_n = input("Enter file name") i_f = open(f_n, 'r') except: print("Input file not found") |
A. | No error |
B. | Assertion error |
C. | Input output error |
D. | Name error |
Answer» B. Assertion error | |
63. |
Which of the following is not an exception handling keyword in Python? |
A. | try |
B. | except |
C. | accept |
D. | finally |
Answer» D. finally | |
64. |
The error displayed in the code shown below is: import itertools l1=(1, 2, 3) l2=[4, 5, 6] l=itertools.chain(l1, l2) print(next(l1)) |
A. | ‘list’ object is not iterator |
B. | ‘tuple’ object is not iterator |
C. | ‘list’ object is iterator |
D. | ‘tuple’ object is iterator |
Answer» C. ‘list’ object is iterator | |
65. |
What is the output of the code shown? def f(x): for i in range(5): yield i g=f(8) print(list(g)) |
A. | [0, 1, 2, 3, 4] |
B. | [1, 2, 3, 4, 5, 6, 7, 8] |
C. | [1, 2, 3, 4, 5] |
D. | [0, 1, 2, 3, 4, 5, 6, 7] |
Answer» B. [1, 2, 3, 4, 5, 6, 7, 8] | |
66. |
What is the output of the following code? def a(): try: f(x, 4) finally: print('after f') print('after f?') a() |
A. | No output |
B. | after f? |
C. | error |
D. | after f |
Answer» D. after f | |
67. |
What is the output of the code shown below? def f(x): yield x+1 print("test") yield x+2 g=f(10) print(next(g)) print(next(g)) |
A. | No output |
B. | 11 test 12 |
C. | 11 test |
D. | 11 |
Answer» C. 11 test | |
68. |
What is the output of the code shown below? #generator def f(x): yield x+1 g=f(8) print(next(g)) |
A. | 8 |
B. | 9 |
C. | 7 |
D. | Error |
Answer» C. 7 | |
69. |
What is the output of the code shown below? x=10 y=8 assert x>y, 'X too small' |
A. | Assertion Error |
B. | 10 8 |
C. | No output |
D. | 108 |
Answer» D. 108 | |
70. |
What happens when ‘1’ == 1 is executed? |
A. | we get a True |
B. | we get a False |
C. | an TypeError occurs |
D. | a ValueError occurs |
Answer» C. an TypeError occurs | |
71. |
What is the output of the following? try: if '1' != 1: raise "someError" else: print("someError has not occurred") except "someError": print ("someError has occurred") |
A. | someError has occurred |
B. | someError has not occurred |
C. | invalid code |
D. | none of the mentioned |
Answer» D. none of the mentioned | |
72. |
What is the output of the following code? def foo(): try: print(1) finally: print(2) foo() |
A. | 1 2 |
B. | 1 |
C. | 2 |
D. | none of the mentioned |
Answer» B. 1 | |
73. |
What is the output of the following code? def foo(): try: return 1 finally: return 2 k = foo() print(k) |
A. | 1 |
B. | 2 |
C. | 3 |
D. | error, there is more than one return statement in a single try-finally block |
Answer» C. 3 | |
74. |
When is the finally block executed? |
A. | when there is no exception |
B. | when there is an exception |
C. | only if some condition that has been specified is satisfied |
D. | always |
Answer» E. | |
75. |
Can one block of except statements handle multiple exception? |
A. | yes, like except TypeError, SyntaxError [,…]. |
B. | yes, like except [TypeError, SyntaxError]. |
C. | no |
D. | none of the mentioned |
Answer» B. yes, like except [TypeError, SyntaxError]. | |
76. |
Is the following code valid? try: # Do something except: # Do something finally: # Do something |
A. | no, there is no such thing as finally |
B. | no, finally cannot be used with except |
C. | no, finally must come before except |
D. | yes |
Answer» C. no, finally must come before except | |
77. |
When will the else part of try-except-else be executed? |
A. | always |
B. | when an exception occurs |
C. | when no exception occurs |
D. | when an exception occurs in to except block |
Answer» D. when an exception occurs in to except block | |
78. |
How many except statements can a try-except block have? |
A. | zero |
B. | one |
C. | more than one |
D. | more than zero |
Answer» E. | |
79. |
Which of these is a private data field? def Demo: def __init__(self): __a = 1 self.__b = 1 self.__c__ = 1 __d__= 1 |
A. | __a |
B. | __b |
C. | __c__ |
D. | __d__ |
Answer» C. __c__ | |
80. |
Methods of a class that provide access to private members of the class are called as ______ and ______ |
A. | getters/setters |
B. | __repr__/__str__ |
C. | user-defined functions/in-built functions |
D. | __init__/__del__ |
Answer» B. __repr__/__str__ | |
81. |
Which of the following is the most suitable definition for encapsulation? |
A. | Ability of a class to derive members of another class as a part of its own definition |
B. | Means of bundling instance variables and methods in order to restrict access to certain class members |
C. | Focuses on variables and passing of variables to functions |
D. | Allows for implementation of elegant software that is well designed and easily modified |
Answer» C. Focuses on variables and passing of variables to functions | |
82. |
Which of these is not a fundamental features of OOP? |
A. | Encapsulation |
B. | Inheritance |
C. | Instantiation |
D. | Polymorphism |
Answer» D. Polymorphism | |
83. |
What is the use of duck typing? |
A. | More restriction on the type values that can be passed to a given method |
B. | No restriction on the type values that can be passed to a given method |
C. | Less restriction on the type values that can be passed to a given method |
D. | Makes the program code smaller |
Answer» D. Makes the program code smaller | |
84. |
What is the biggest reason for the use of polymorphism? |
A. | It allows the programmer to think at a more abstract level |
B. | There is less program code to write |
C. | The program will have a more elegant design, and will be easier to maintain and update |
D. | Program code takes up less space |
Answer» D. Program code takes up less space | |
85. |
Which of the following best describes polymorphism? |
A. | Ability of a class to derive members of another class as a part of its own definition |
B. | Means of bundling instance variables and methods in order to restrict access to certain class members |
C. | Focuses on variables and passing of variables to functions |
D. | Allows for objects of different types and behaviour to be treated as the same general type |
Answer» E. | |
86. |
What is the output of the following piece of code? class A: def __init__(self): self._x = 5 class B(A): def display(self): print(self._x) def main(): obj = B() obj.display() main() |
A. | Error, invalid syntax for object declaration |
B. | Nothing is printed |
C. | 5 |
D. | Error, private class member can’t be accessed in a subclass |
Answer» D. Error, private class member can’t be accessed in a subclass | |
87. |
What is the output of the following piece of code when executed in the Python shell? >>> class A: pass >>> class B(A): pass >>> obj=B() >>> isinstance(obj,A) |
A. | True |
B. | False |
C. | Wrong syntax for isinstance() method |
D. | Invalid method for classes |
Answer» B. False | |
88. |
Which of the following statements isn’t true? |
A. | A non-private method in a superclass can be overridden |
B. | A derived class is a subset of superclass |
C. | The value of a private variable in the superclass can be changed in the subclass |
D. | When invoking the constructor from a subclass, the constructor of superclass is automatically invoked |
Answer» D. When invoking the constructor from a subclass, the constructor of superclass is automatically invoked | |
89. |
What does single-level inheritance mean? |
A. | A subclass derives from a class which in turn derives from another class |
B. | A single superclass inherits from multiple subclasses |
C. | A single subclass derives from a single superclass |
D. | Multiple base classes inherit a single derived class |
Answer» D. Multiple base classes inherit a single derived class | |
90. |
What type of inheritance is illustrated in the following piece of code? class A(): pass class B(A): pass class C(B): pass |
A. | Multi-level inheritance |
B. | Multiple inheritance |
C. | Hierarchical inheritance |
D. | Single-level inheritance |
Answer» B. Multiple inheritance | |
91. |
What type of inheritance is illustrated in the following piece of code? class A(): pass class B(): pass class C(A,B): pass |
A. | Multi-level inheritance |
B. | Multiple inheritance |
C. | Hierarchical inheritance |
D. | Single-level inheritance |
Answer» C. Hierarchical inheritance | |
92. |
What does built-in function help do in context of classes? |
A. | Determines the object name of any value |
B. | Determines the class identifiers of any value |
C. | Determines class description of any built-in type |
D. | Determines class description of any user-defined built-in type |
Answer» D. Determines class description of any user-defined built-in type | |
93. |
Which of the following is not a type of inheritance? |
A. | Double-level |
B. | Multi-level |
C. | Single-level |
D. | Multiple |
Answer» B. Multi-level | |
94. |
What does built-in function type do in context of classes? |
A. | Determines the object name of any value |
B. | Determines the class name of any value |
C. | Determines class description of any value |
D. | Determines the file name of any value |
Answer» C. Determines class description of any value | |
95. |
What is the output of the following piece of code? class A: def __init__(self, x= 1): self.x = x class der(A): def __init__(self,y = 2): super().__init__() self.y = y def main(): obj = der() print(obj.x, obj.y) main() |
A. | Error, the syntax of the invoking method is wrong |
B. | The program runs fine but nothing is printed |
C. | 1 0 |
D. | 1 2 |
Answer» E. | |
96. |
What is the output of the following piece of code? class Test: def __init__(self): self.x = 0 class Derived_Test(Test): def __init__(self): Test.__init__(self) self.y = 1 def main(): b = Derived_Test() print(b.x,b.y) main() |
A. | Error because class B inherits A but variable x isn’t inherited |
B. | 0 0 |
C. | 0 1 |
D. | Error, the syntax of the invoking method is wrong |
Answer» D. Error, the syntax of the invoking method is wrong | |
97. |
Suppose B is a subclass of A, to invoke the __init__ method in A from B, what is the line of code you should write? |
A. | A.__init__(self) |
B. | B.__init__(self) |
C. | A.__init__(B) |
D. | B.__init__(A) |
Answer» B. B.__init__(self) | |
98. |
What is the output of the following piece of code? class A(): def disp(self): print("A disp()") class B(A): pass obj = B() obj.disp() |
A. | Invalid syntax for inheritance |
B. | Error because when object is created, argument must be passed |
C. | Nothing is printed |
D. | A disp() |
Answer» E. | |
99. |
What is the output of the following piece of code? class Test: def __init__(self): self.x = 0 class Derived_Test(Test): def __init__(self): self.y = 1 def main(): b = Derived_Test() print(b.x,b.y) main() |
A. | 0 1 |
B. | 0 0 |
C. | Error because class B inherits A but variable x isn’t inherited |
D. | Error because when object is created, argument must be passed like Derived_Test(1) |
Answer» D. Error because when object is created, argument must be passed like Derived_Test(1) | |
100. |
Which of the following statements is wrong about inheritance? |
A. | Protected members of a class can be inherited |
B. | The inheriting class is called a subclass |
C. | Private members of a class can be inherited and accessed |
D. | Inheritance is one of the features of OOP |
Answer» D. Inheritance is one of the features of OOP | |