- Home
- Subjects
- Data Science
- Python
Python MCQs · Page 13
595 multiple choice questions with answers in Data Science.
What is the output of the following Python code snippet?
s = 'hello'
s[0] = 'H'
s[0] = 'H'
What is the output of print(sorted([3, 1, 2], key=lambda x: x)) in Python?
print(sorted([3, 1, 2], key=lambda x: x))
What is the output of print('Python'[::-1]) in Python?
print('Python'[::-1])
What is PEP 8 in Python?
What is the output of print('' or 'hello') in Python?
print('' or 'hello')
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 keyword turns a function into a generator in Python?
What is the output of the following Python code snippet?
def f(**kwargs):
return kwargs
print(f(a=1, b=2))
return kwargs
print(f(a=1, b=2))
What is the output of print('th' in 'Python') in Python?
print('th' in 'Python')
What is the output of the following Python code snippet?
try:
assert 1 == 2
except AssertionError:
print('AssertionError')
assert 1 == 2
except AssertionError:
print('AssertionError')
Which module is used to create abstract base classes in Python?
What is the output of print(any([0, 0, 1])) in Python?
print(any([0, 0, 1]))
What does LEGB stand for in Python scope resolution?
What is the output of the following Python code snippet?
try:
'python'.index('z')
except Exception as e:
print(type(e).__name__)
'python'.index('z')
except Exception as e:
print(type(e).__name__)
What is the main advantage of generators over lists in Python?
What does json.loads() do in Python?
What is the output of print(list(filter(lambda x: x % 2 == 0, [1, 2, 3, 4]))) in Python?
print(list(filter(lambda x: x % 2 == 0, [1, 2, 3, 4])))
What is the output of print('Python'.startswith('Py')) in Python?
print('Python'.startswith('Py'))
What is the output of print('Python'.replace('P', 'J')) in Python?
print('Python'.replace('P', 'J'))
What is the output of the following Python code snippet?
x = 5
print(1
What is the output of print(sorted(['banana', 'pie', 'apple'], key=len)) in Python?
print(sorted(['banana', 'pie', 'apple'], key=len))