# Python MCQ Questions Set-3

a = (1, 2)
a +=1

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

## 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.

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

Ans: D

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

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 = {}
if country in counter:
counter[country] += 1
else:
counter[country] = 1

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
dictionary = ’10’
del dictionary
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

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