- Home
- Subjects
- Data Science
- Python
Python MCQs · Page 14
595 multiple choice questions with answers in Data Science.
What is the purpose of the if __name__ == '__main__': block in Python?
What does the assert statement do in Python?
What does setdefault(key, default) do in Python?
What does self refer to in an instance method in Python?
What does append() return in Python?
What is the output of print(1 in {'a': 1}) in Python?
print(1 in {'a': 1})
Which command creates a virtual environment 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 print('python'.find('z')) in Python?
print('python'.find('z'))
What is the output of print('Python'[1:4]) in Python?
print('Python'[1:4])
When does the else block of a try statement run in Python?
What is the time complexity of the in operator on a list in Python?
What is the output of the following Python code snippet?
x = 5
def f():
x = 10
f()
print(x)
def f():
x = 10
f()
print(x)
How do you define a custom exception in Python?
What does sys.getrefcount(obj) return in Python?
What is the output of the following Python code snippet?
a = [1, 2, 3]
a.append(4)
print(a)
a.append(4)
print(a)
What is the output of print(0.1 + 0.2 == 0.3) in Python?
print(0.1 + 0.2 == 0.3)
What is the output of the following Python code snippet?
def fact(n):
return 1 if n
What is the output of the following Python code snippet?
def greet(name='Guest'):
return f'Hello, {name}'
print(greet())
return f'Hello, {name}'
print(greet())
What does enumerate(items, start=1) do in Python?
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())
What is the output of the following Python code snippet?
i = 0
while i