Python MCQ Questions Set-3

Q1: What is the output of the following code −

a = (1, 2)
a[0] +=1

a)(1,1,2)
b)2
c)Type Error
d)Syntax Error

Answer: C

Q2: Suppose we have two sets A & B, then A<B is:

a)True if len(A) is less than len(B).
b)True if A is a proper subset of B.
c)True if the elements in A when compared are less than the elements in B.
d)True if A is a proper superset of B.

Answer : B

Q3: Select the reserved keyword in python

a) else
b) import
c) raise
d) All of these

Ans: D

Q4: Syntax of constructor in Python.

a) def init()
b) def init()
c) init()
d) All of these

Ans: A

Q5: What is correct syntax to copy one list into another?

a) listA = listB[]
b) listA = listB[:]
c) listA = listB[]()
d) listA = listB

Ans: B

Q6: If a=’cpp’, b=’buzz’ then what is the output of:
c = a-b
print(c)

a)cpp-buzz
b)cppbuzz
c)TypeError: unsupported operand
d)None of the above

Ans: C

Q7:What is the output of following code?

a = True
b = False
c = True
if not a or b:
print (“a”)
elif not a or not b and c:
print (“b”)
elif not a or b or not b and a:
print (“c”)
else:
print (“d”)

a)a
b)b
c)c
d)d

Ans B

Q8: What is the output of following code?

class test:
def init(self):
print (“Hello World”)
def init(self):
print (“Bye World”)
obj=test()
a)Hello World
b)Compilation Error
c)Bye World
d)Ambiguity

Ans: C

Q9: Which of the following is an invalid statement?

a)abc = 1,000,000
b)a b c = 1000 2000 3000
c)a,b,c = 1000, 2000, 3000
d)a_b_c = 1,000,000

Ans: B

Q10: Is it possible to use round function without any argument like round()

a) Yes
b) No

Ans:: B

Q11: What is an exception

a)Error
b)Compile time error
c)Run time error
d)None

Ans: C

Q12: Predict the output of following Python Programs.

class Acc:
def init(self, id):
self.id = id
id = 555

acc = Acc(111)
print (acc.id)
a)111
b)555
c)222
d)111555

Ans: A

Q13:Predict the output of following Python Programs.

counter = {}
def addToCounter(country):
if country in counter:
counter[country] += 1
else:
counter[country] = 1

addToCounter(‘China’)
addToCounter(‘Japan’)
addToCounter(‘china’)
print (len(counter))
a)3
b)2
c)1
d)0

Ans 3

Q 14: Predict the output of following Python Program

count = 1
def doThis():
global count
for i in (1, 2, 3):
count += 1
doThis()
print (count)
a)4
b)3
c)2
d)0

ANS: A

Q 15:

dictionary = {1:’1′, 2:’2′, 3:’3′}
del dictionary[1]
dictionary[1] = ’10’
del dictionary[2]
print (len(dictionary))
a)4
b)3
c)2
d)0

ANS: C

Q 16:What is the output of the following piece of 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()

a)2 7
b)1 5
c)1 7
d)2 5

ANS:C

Q17: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 Python

Ans:a

Q18: 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

Ans C

Q19:Which of the following is not a type of inheritance?

a)Single-level
b)Double-level
c)Multiple
d)Multi-level

Ans:b

Q20: What is the output of the following piece of code?

class A:
def init(self):
self.__x = 1
class B(A):
def display(self):
print(self.__x)
def main():
obj = B()
obj.display()
main()
a)1
b)0
c)1 0
d)Error

Ans: d

Q21: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)having more than one form.

Ans d

Q22: What is the output of the following piece of code?

class A:
def init(self,x=3):
self._x = x

class B(A):
def init(self):
super().init(5)

def display(self):
    print(self._x)

def main():
obj = B()
obj.display()
main()
a) 5
b)3
c)Error, class member x has two values
d)Error, protected class member can’t be accessed in a subclass

Ans: a

Q23: What is the output of the following piece of code?

class A:
def str(self):
return ‘1’

class B(A):
def init(self):
super().init()

class C(B):
def init(self):
super().init()

def main():
obj1 = B()
obj2 = A()
obj3 = C()
print(obj1, obj2,obj3)

main()

a)1 1 1
b)1 2 3
c) ‘1’ ‘1’ ‘1’
d)An exception is thrown

Ans:a

Q 24:A class in which one or more methods are only implemented to raise an exception is called an abstract class. True or False?

a)True
b)False

Ans: b

Q25: Inheritance shows .

a) IS A Relationship
b) HAS A Relationship
c) USES Relationship
d)None of the above.

Ans: a

Leave a Reply

Your email address will not be published. Required fields are marked *