CARVIEW |
Exception Handling and Libraries in Python - Quiz
A quiz covering Python exception handling, generators, context managers, NumPy, and Pandas fundamentals.
Question 1
What will be the output of the following code?
try:
x = 10 / 0
except ZeroDivisionError:
print("Error")
finally:
print("Done")
Error
Done
Error Done
Program crash
Question 2
Which statement is used to manually raise an exception in Python?
throw
raise
except
assert
Question 3
Which keyword is used to return values one at a time in a generator function?
return
yield
next
continue
Question 4
Which methods must a custom context manager class implement?
__start__ and __stop__
__enter__ and __exit__
open and close
begin and end
Question 5
What will this code print?
class Demo:
def __enter__(self):
print("Enter")
return self
def __exit__(self, *args):
print("Exit")
with Demo():
print("Inside")
Enter
Enter Inside
Enter Inside Exit
Inside Exit
Question 6
Which function is used to create an array of all zeros in NumPy?
zeros()
ones()
empty()
array()
Question 7
What will be the output of the following code?
import numpy as np
arr = np.array([1,2,3])
print(arr * 2)
[2 4 6]
[1 2 3 1 2 3]
Error
[1 2 3]
Question 9
Which Pandas function is used to remove duplicate rows from a DataFrame?
drop_null()
drop_duplicates()
remove_duplicates()
delete_rows()
Question 10
If a CSV file has an extra index column like Unnamed: 0, how can we remove it?
df.remove('Unnamed: 0')
df.delete('Unnamed: 0')
df.drop(columns=['Unnamed: 0'])
df.remove_column('Unnamed: 0')
There are 10 questions to complete.