Loading

Quipoin Menu

Learn • Practice • Grow

python / Modules and Packages
mcq
Direction: Choose the correct option

Q1.

What is a module in Python?
A. A package
B. A file containing Python code
C. A script
D. A library of functions
Direction: Choose the correct option

Q2.

How do you import a module named 'math'?
A. import math
B. using math
C. include math
D. require math
Direction: Choose the correct option

Q3.

What is the difference between `import math` and `from math import sqrt`?
A. `import math` imports only sqrt
B. `from math import sqrt` imports the whole module
C. They are the same
D. `import math` imports the whole module; `from math import sqrt` imports only sqrt
Direction: Choose the correct option

Q4.

What is a package in Python?
A. A library of functions
B. A collection of scripts
C. A directory containing modules and an __init__.py file
D. A single module file
Direction: Choose the correct option

Q5.

How do you import a module from a package?
A. from package import module
B. import package.module
C. import package
D. Both A and C
Direction: Choose the correct option

Q6.

What is the purpose of `if __name__ == '__main__':`?
A. To define the main function
B. To run code only when the script is executed directly, not when imported
C. To check module version
D. To import main module
Direction: Choose the correct option

Q7.

What does `dir(math)` do?
A. Executes math
B. Lists all attributes of the math module
C. Imports math
Direction: Choose the correct option

Q8.

How do you create an alias for a module?
A. using math as m
B. import math as m
C. from math import *
D. import math
Direction: Choose the correct option

Q9.

What is the __init__.py file used for?
A. To mark a directory as a Python package
B. All of the above
C. To run code on import
D. To initialize the package
Direction: Choose the correct option

Q10.

Where does Python look for modules?
A. In the current directory and in directories listed in sys.path
B. Only in the Python installation directory
C. In the user's home directory
D. Only in the current directory