Question 1
When using csv.DictReader, how are keys for each dictionary determined?
From the filename
From the first row of the CSV file
From the row index values
From Python’s default dictionary keys
Question 2
Inside a virtual environment, you install requests. How do you confirm where it got installed?
pip list
which python (Linux/macOS) / where python (Windows)
pip show requests
All of the above
Question 3
On Windows Command Prompt, which command activates a virtual environment named env?
source env/bin/activate
env\Scripts\activate
activate env
Scripts/activate.sh
Question 4
What will be the output of the following code?
import math
print(math.sqrt(16))
print(math.pi)
4, 3.141592653589793
sqrt(16), pi
Error: sqrt not defined
16, 3.14
Question 5
What will be the output of the following code?
with open("example.txt", "w") as f:
f.write("Hello, Python!")
print(f.closed)
False
True
None
Error
Question 6
Why is using a context manager with files (with open("file.txt") as f:) better than calling open() and close() manually?
It makes the file object immutable
It avoids syntax errors
It ensures the file is closed even if an exception occurs
It increases performance by 2x
Question 7
What is the type of res here?
res = (x*x for x in range(5))
print(type(res))
<class 'list'>
<class 'tuple'>
<class 'generator'>
<class 'set'>
Question 8
Which of the following is NOT an advantage of using yield?
Memory efficiency
Lazy evaluation
State retention
Random access to elements
Question 9
Find the output
sq = (x*x for x in range(3))
print(next(sq))
print(next(sq))
print(next(sq))
print(next(sq))
0, 1, 4, StopIteration
1, 4, 9, StopIteration
0, 1, 4, 9
Error
There are 25 questions to complete.