- Home
- MCQs by exam
- Python Interview OOP
- Data Science
Python Interview OOP MCQs – Data Science · Page 2
53 multiple choice questions typical of the Python Interview OOP exam, with answers and explanations. Switch on practice mode to test yourself first.
What does the @dataclass decorator generate automatically in Python?
What is the difference between __str__ and __repr__ in Python?
What is the output of the following Python code snippet?
class Point:
def __init__(self, x, y):
self.x, self.y = x, y
def __repr__(self):
return f'Point({self.x}, {self.y})'
print(Point(1, 2))
def __init__(self, x, y):
self.x, self.y = x, y
def __repr__(self):
return f'Point({self.x}, {self.y})'
print(Point(1, 2))
What is polymorphism in Python?
Which function checks whether a class inherits from another in Python?
How can you see a class's MRO in Python?
What is the output of the following Python code snippet?
class A:
def __init__(self, x):
self.x = x
print(A(10).x)
def __init__(self, x):
self.x = x
print(A(10).x)
Which module is used to create abstract base classes in Python?
What does self refer to in an instance method in Python?
What is the output of the following Python code snippet?
class C:
@property
def pi(self): return 3.14
print(C().pi)
@property
def pi(self): return 3.14
print(C().pi)
What is the output of print(isinstance(int, object)) in Python?
print(isinstance(int, object))
What is the output of the following Python code snippet?
class Animal:
def speak(self): return 'Animal sound'
class Dog(Animal):
def speak(self): return 'Dog barks'
print(Dog().speak())
def speak(self): return 'Animal sound'
class Dog(Animal):
def speak(self): return 'Dog barks'
print(Dog().speak())
Which special method allows an object to be called like a function in Python?
What does a single leading underscore (_x) in a name signify in Python?
What is the output of the following Python code snippet?
class A:
n = 0
def __init__(self):
A.n += 1
A(); A()
print(A.n)
n = 0
def __init__(self):
A.n += 1
A(); A()
print(A.n)
Which special method makes two objects comparable with == in Python?
What is the name of the constructor-like method in a Python class?
What is the output of the following Python code snippet?
class A:
def __init__(self): print('A', end=' ')
class B(A):
def __init__(self):
print('B', end=' ')
super().__init__()
B()
def __init__(self): print('A', end=' ')
class B(A):
def __init__(self):
print('B', end=' ')
super().__init__()
B()