- Home
- Subjects
- Data Science
- Python
Python MCQs · Page 5
595 multiple choice questions with answers in Data Science.
What is the output of the following Python code snippet?
x = 5
print(f'{x = }')
print(f'{x = }')
What does yield from 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 a weak reference in Python?
What does re.compile() provide in Python?
What is the output of print(bool([])) in Python?
print(bool([]))
What is the output of the following Python code snippet?
a = [1, 2]
a += [3]
print(a)
a += [3]
print(a)
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 class in the csv module reads rows as dictionaries in Python?
What is the output of the following Python code snippet?
import re
print(re.findall(r'[cb]at', 'cat bat rat'))
print(re.findall(r'[cb]at', 'cat bat rat'))
Which pandas function reads a CSV file into a DataFrame in Python?
Which method counts missing values per column in Python?
What does the dir() function do with no arguments in Python?
What is the output of print(list(map(str.lower, ['A', 'B', 'C']))) in Python?
print(list(map(str.lower, ['A', 'B', 'C'])))
What does python -m http.server do?
What does deque(maxlen=3) do when a fourth item is appended in Python?
What is the output of the following Python code snippet?
d = {'a': 2, 'b': 1}
print({v: k for k, v in d.items()})
print({v: k for k, v in d.items()})
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 print('abc'[::2]) in Python?
print('abc'[::2])
What is the output of print(10 ** 100 < float('inf')) in Python?
print(10 ** 100
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))