Python OOPs and Functions
Python OOPs and Functions
MCQ’s
Ans-> None
3.The output of the expression [ chr(i) for i in [65, 66, 67] ] is _______.
Ans ->[1, 4]
Ans ->False
1.Which of the following method is used by a user-defined class to support '+' operator?
2.Which methods are invoked on entering into and exiting from the block of code written in 'with'
statement?
__metaclass__ = B
4. what is the output of the code.
class A:
self.x = x
self.y = y
def __str__(self):
def f1():
a = A(12, 3)
b = A(3, 12)
if (a == b):
print(b != a)
print(a)
f1()
Ans ->False
A(x: 12, y: 3)
5. what Is the output of the code:
class A:
self.a = a
def f1(self):
self.a += 10
class B(A):
A.__init__(self, 4)
self.b = b
def f1(self):
self.b += 10
x = B()
x.f1()
print(x.a,'-', x.b)
Ans-> 4 - 10
3. Which of the following is not a way to import the module 'm1' or the
functions 'f1' and 'f2' defined in it?
Ans-> import f1, f2 from m1
2.
class grandpa(object):
pass
class father(grandpa):
pass
class mother(object):
pass
print(child.__mro__)
Ans->
5.If a list has 5 elements, then which of the following exceptions is raised
when 8th element is accessed?
Ans-> IndexError
Ans-> [15,24]
7. Which of the following modules contain functions that create iterators for
efficient looping?
Ans-> itertools
Ans-> [6,4,1]