- Home
- MCQs by exam
- Python Interview OOP
- Data Science
Python Interview OOP MCQs – Data Science
53 multiple choice questions typical of the Python Interview OOP exam, with answers and explanations. Switch on practice mode to test yourself first.
What is the diamond problem in multiple inheritance in Python?
What is composition in OOP in Python?
What is a metaclass in Python?
What is the output of the following Python code snippet?
class M:
@staticmethod
def mul(a, b): return a * b
print(M.mul(3, 4))
@staticmethod
def mul(a, b): return a * b
print(M.mul(3, 4))
What is the output of the following Python code snippet?
from dataclasses import dataclass
@dataclass
class P:
x: int
y: int
print(P(1, 2))
@dataclass
class P:
x: int
y: int
print(P(1, 2))
What is duck typing in Python?
What is the output of the following Python code snippet?
class A:
@classmethod
def f(cls): return 'Cls'
print(A.f())
@classmethod
def f(cls): return 'Cls'
print(A.f())
What is the Singleton pattern in Python?
What is the output of the following Python code snippet?
class A:
def __init__(self): self.x = 1
print(A().__dict__)
def __init__(self): self.x = 1
print(A().__dict__)
What does @dataclass(frozen=True) do in Python?
What is the output of the following Python code snippet?
class CM:
def __enter__(self):
print('enter', end=' ')
def __exit__(self, *a):
print('exit')
with CM():
pass
def __enter__(self):
print('enter', end=' ')
def __exit__(self, *a):
print('exit')
with CM():
pass
What is the output of the following Python code snippet?
class A:
def f(self): return 'A'
class B(A):
def f(self): return 'B'
print(B().f())
def f(self): return 'A'
class B(A):
def f(self): return 'B'
print(B().f())
Which is called first when creating an instance: __new__ or __init__ in Python?
What is a common use of a classmethod in Python?
What is the output of the following Python code snippet?
from collections import namedtuple
P = namedtuple('Point', 'x y')
print(P(1, 2))
P = namedtuple('Point', 'x y')
print(P(1, 2))
What happens to hashing when you define __eq__ without __hash__ in Python?
What is the output of the following Python code snippet?
class A:
__slots__ = ('x',)
a = A()
try:
a.y = 10
except AttributeError:
print('AttributeError')
__slots__ = ('x',)
a = A()
try:
a.y = 10
except AttributeError:
print('AttributeError')
What is the output of the following Python code snippet?
from dataclasses import dataclass, field
@dataclass
class C:
items: list = field(default_factory=list)
print(C().items)
@dataclass
class C:
items: list = field(default_factory=list)
print(C().items)
What is the output of the following Python code snippet?
class A:
def __init__(self): print('A init')
class B(A):
def __init__(self): print('B init')
B()
def __init__(self): print('A init')
class B(A):
def __init__(self): print('B init')
B()