

InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
1. |
Which of the following blocks will be executed whether an exception is thrown or not?(a) except(b) else(c) finally(d) assertThis question was addressed to me in unit test.Origin of the question is Exception Handling in chapter Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The correct option is (c) finally |
|
2. |
_______________________ exceptions are raised as a result of an error in opening a particular file.(a) ValueError(b) TypeError(c) ImportError(d) IOErrorThis question was addressed to me in an online interview.Origin of the question is Exception Handling in chapter Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Correct answer is (d) IOERROR |
|
3. |
An exception is ____________(a) an object(b) a special function(c) a standard module(d) a moduleI have been asked this question during an interview for a job.This interesting question is from Exception Handling topic in chapter Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The CORRECT option is (a) an OBJECT |
|
4. |
Syntax errors are also known as parsing errors.(a) True(b) FalseThe question was asked in examination.This question is from Exception Handling topic in division Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Correct ANSWER is (a) TRUE |
|
5. |
Which of the following is not a standard exception in Python?(a) NameError(b) IOError(c) AssignmentError(d) ValueErrorThis question was posed to me in my homework.My question is from Exception Handling topic in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Correct option is (C) AssignmentError |
|
6. |
Which of the following statements is true?(a) The standard exceptions are automatically imported into Python programs(b) All raised standard exceptions must be handled in Python(c) When there is a deviation from the rules of a programming language, a semantic error is thrown(d) If any exception is thrown in try block, else block is executedThe question was asked in an interview for job.I need to ask this question from Exception Handling in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Correct choice is (a) The standard exceptions are AUTOMATICALLY imported into Python programs |
|
7. |
What happens when ‘1’ == 1 is executed?(a) we get a True(b) we get a False(c) an TypeError occurs(d) a ValueError occursThis question was posed to me in an interview for job.My question is taken from Exception Handling in portion Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Right option is (b) we GET a FALSE |
|
8. |
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) alwaysThe question was asked in an international level competition.The origin of the question is Exception Handling in division Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The correct ANSWER is (d) always |
|
9. |
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 mentionedThe question was posed to me in an internship interview.I'd like to ask this question from Exception Handling in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The correct option is (a) yes, like except TYPEERROR, SYNTAXERROR [,…] |
|
10. |
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 blockI have been asked this question in unit test.My doubt is from Exception Handling in division Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Right answer is (C) when no exception occurs |
|
11. |
How many except statements can a try-except block have?(a) zero(b) one(c) more than one(d) more than zeroI got this question in an interview for internship.Asked question is from Exception Handling topic in chapter Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» RIGHT CHOICE is (d) more than zero To explain: There has to be at LEAST one except STATEMENT. |
|
12. |
Which of the following is false about protected class members?(a) They begin with one underscore(b) They can be accessed by subclasses(c) They can be accessed by name mangling method(d) They can be accessed within a classI got this question by my school principal while I was bunking the class.The question is from Encapsulation in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Correct ANSWER is (C) They can be accessed by name MANGLING method |
|
13. |
The purpose of name mangling is to avoid unintentional access of private class members.(a) True(b) FalseThe question was posed to me in an interview.My doubt stems from Encapsulation in chapter Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Correct choice is (a) True |
|
14. |
Private members of a class cannot be accessed.(a) True(b) FalseThis question was addressed to me by my college professor while I was bunking the class.Asked question is from Encapsulation topic in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Correct OPTION is (b) False |
|
15. |
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__This question was posed to me in class test.This question is from Encapsulation topic in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» RIGHT choice is (a) getters/setters To EXPLAIN I would say: The PURPOSE of getters and setters is to get(RETURN) and SET(assign) private instance variables of a class. |
|
16. |
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 modifiedThe question was asked in a job interview.I would like to ask this question from Encapsulation in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The correct CHOICE is (b) Means of bundling instance VARIABLES and methods in order to restrict access to certain class MEMBERS |
|
17. |
Which of these is not a fundamental features of OOP?(a) Encapsulation(b) Inheritance(c) Instantiation(d) PolymorphismThis question was posed to me in exam.This interesting question is from Encapsulation topic in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» CORRECT choice is (C) Instantiation To EXPLAIN: Instantiation simply refers to creation of an instance of class. It is not a FUNDAMENTAL feature of OOP. |
|
18. |
Which of the following statements is true?(a) A non-private method in a superclass can be overridden(b) A subclass method can be overridden by the superclass(c) A private method in a superclass can be overridden(d) Overriding isn’t possible in PythonThe question was asked during an interview.My doubt stems from Polymorphism in portion Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Right OPTION is (a) A non-private method in a superclass can be overridden |
|
19. |
Overriding means changing behaviour of methods of derived class methods in the base class.(a) True(b) FalseThis question was posed to me at a job interview.I would like to ask this question from Polymorphism in portion Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The CORRECT option is (b) False |
|
20. |
A class in which one or more methods are only implemented to raise an exception is called an abstract class.(a) True(b) FalseI have been asked this question in examination.This intriguing question originated from Polymorphism topic in chapter Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The correct choice is (a) True |
|
21. |
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 smallerI had been asked this question in an international level competition.My question is based upon Polymorphism in portion Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The correct choice is (C) Less restriction on the type values that can be passed to a given method |
|
22. |
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 spaceI had been asked this question in exam.Query is from Polymorphism in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Right CHOICE is (c) The program will have a more elegant DESIGN and will be EASIER to maintain and update |
|
23. |
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 typeThis question was posed to me in homework.My question is based upon Polymorphism topic in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Right option is (d) Allows for OBJECTS of different TYPES and behaviour to be treated as the same general type |
|
24. |
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 typeI had been asked this question in a national level competition.This is a very interesting question from Inheritance topic in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The correct choice is (c) DETERMINES class description of any built-in TYPE |
|
25. |
Which of the following is not a type of inheritance?(a) Double-level(b) Multi-level(c) Single-level(d) MultipleI got this question during an interview for a job.I need to ask this question from Inheritance topic in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The CORRECT answer is (a) Double-level |
|
26. |
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 valueI got this question during an online interview.This interesting question is from Inheritance topic in portion Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» RIGHT answer is (B) Determines the class name of any value Easiest explanation - For EXAMPLE: >>> type((1,)) gives |
|
27. |
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)The question was asked in homework.This is a very interesting question from Inheritance topic in portion Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The CORRECT choice is (a) A.__init__(self) |
|
28. |
What does print(Test.__name__) display (assuming Test is the name of the class)?(a) ()(b) Exception is thrown(c) Test(d) __main__I got this question in unit test.Asked question is from Classes and Objects topic in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Right answer is (c) Test |
|
29. |
__del__ method is used to destroy instances of a class.(a) True(b) FalseThe question was posed to me during an interview for a job.The query is from Classes and Objects in division Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The correct option is (a) True |
|
30. |
What is Instantiation in terms of OOP terminology?(a) Deleting an instance of class(b) Modifying an instance of class(c) Copying an instance of class(d) Creating an instance of classI got this question during an interview.This interesting question is from Classes and Objects in division Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» RIGHT choice is (d) Creating an INSTANCE of class Explanation: Instantiation REFERS to creating an object/instance for a class. |
|
31. |
What is getattr() used for?(a) To access the attribute of the object(b) To delete an attribute(c) To check if an attribute exists or not(d) To set an attributeI got this question in semester exam.The above asked question is from Classes and Objects in chapter Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The correct CHOICE is (a) To access the ATTRIBUTE of the OBJECT |
|
32. |
What is setattr() used for?(a) To access the attribute of the object(b) To set an attribute(c) To check if an attribute exists or not(d) To delete an attributeThis question was addressed to me in exam.The doubt is from Classes and Objects topic in chapter Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The CORRECT option is (B) To SET an attribute |
|
33. |
_____is used to create an object.(a) class(b) constructor(c) User-defined functions(d) In-built functionsThis question was addressed to me during a job interview.Query is from Classes and Objects topic in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Correct answer is (b) constructor |
|
34. |
_____ represents an entity in the real world with its identity and behaviour.(a) A method(b) An object(c) A class(d) An operatorThe question was asked by my school teacher while I was bunking the class.The doubt is from Classes and Objects topic in section Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Right OPTION is (B) An OBJECT |
|
35. |
Which function overloads the // operator?(a) __div__()(b) __ceildiv__()(c) __floordiv__()(d) __truediv__()This question was addressed to me in an interview.I need to ask this question from Operator Overloading topic in division Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The CORRECT CHOICE is (C) __floordiv__() |
|
36. |
Which operator is overloaded by the __or__() function?(a) ||(b) |(c) //(d) /I have been asked this question in an interview for job.Question is from Operator Overloading in portion Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The correct answer is (B) | |
|
37. |
Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?(a) __add__(), __str__()(b) __str__(), __add__()(c) __sum__(), __str__()(d) __str__(), __sum__()I got this question in an interview.My question is from Operator Overloading in portion Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Right OPTION is (a) __add__(), __str__() |
|
38. |
Which function overloads the >> operator?(a) __more__()(b) __gt__()(c) __ge__()(d) none of the mentionedI have been asked this question at a job interview.This question is from Operator Overloading in chapter Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» Right ANSWER is (d) NONE of the mentioned |
|
39. |
Which operator is overloaded by __lg__()?(a) (c) !=(d) none of the mentionedI had been asked this question in an interview for internship.The above asked question is from Operator Overloading topic in division Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The CORRECT ANSWER is (d) NONE of the mentioned |
|
40. |
Which function overloads the == operator?(a) __eq__()(b) __equ__()(c) __isequal__()(d) none of the mentionedThis question was posed to me in a national level competition.Question is taken from Operator Overloading topic in chapter Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python |
Answer» The correct choice is (a) __eq__() |
|