Python Modules and Imports Quiz
A 35-question quiz covering import syntax, namespace management, standard libraries, and module organization.
Question 1
What is the primary purpose of a module in Python?
Question 2
Which keyword is used to bring a module into your current script?
Question 3
Analyze the code below. How do you access the `sqrt` function?
import mathQuestion 4
What does the syntax `from module import item` do?
Question 5
Why is `from module import *` generally discouraged?
Question 6
Analyze the code below. What is the correct way to call the function?
import datetime as dtQuestion 7
Which built-in module would you use to interact with the operating system (e.g., file paths, environment variables)?
Question 8
Where does Python look for modules when you try to import them?
Question 9
Analyze the code below. What happens if `my_module.py` contains `print('Hello')`?
import my_module
import my_moduleQuestion 10
What is the purpose of the `__name__ == '__main__'` check?
if __name__ == '__main__':
main()Question 11
Which module provides mathematical functions like `sin`, `cos`, and `pi`?
Question 12
How do you import two specific functions `func1` and `func2` from `mymodule`?
Question 13
What is a package in Python?
Question 14
Which module allows you to generate random numbers?
Question 15
Analyze the code below. What is `sys.argv`?
import sys
print(sys.argv)Question 16
What happens if you try to import a module that is not installed or found?
Question 17
How can you list all names defined in a module?
Question 18
Analyze the code below. What is the effect of `del math`?
import math
del mathQuestion 19
Which statement is true about standard library modules?
Question 20
What is the correct way to import a module named `config` located in a subfolder named `utils`?
Question 21
Analyze the code below. What is the result?
from math import pi as pie
print(pie)Question 22
Which module is used for handling JSON data?
Question 23
What is a circular import?
Question 24
How can you reload a module that has already been imported (e.g., during development)?
Question 25
What is the file `__init__.py` used for?
Question 26
Which module provides regular expression matching operations?
Question 27
Analyze the code below. What is the issue?
from math import *
print(sqrt(4))
print(tan(0))Question 28
What variable contains the location of the module file?
Question 29
Which standard module allows you to work with dates and times?
Question 30
How do you install a third-party module like `requests`?
Question 31
What is the benefit of using absolute imports over relative imports?
Question 32
Analyze the code below. What is `m`?
import math as mQuestion 33
Which module helps in parsing command-line arguments in a user-friendly way?
Question 34
What does `import sys, os` do?
Question 35
Why should imports be placed at the top of the file?
