Python Modules - MCQs with Answers and Explanations
1. Which of the following is used to import a module in Python?
a) import
b) using
c) include
d) require
Answer: a) import
Explanation: Python uses the 'import' statement to include modules in a script.
2. What is a module in Python?
a) A file containing Python definitions and statements
b) A function
c) A class
d) A package of Java code
Answer: a) A file containing Python definitions and statements
Explanation: A module is a file that contains Python code, such as functions and variables.
3. What is the purpose of the 'from' keyword in Python modules?
a) To rename a module
b) To import specific attributes or functions from a module
c) To delete a module
d) To define a module
Answer: b) To import specific attributes or functions from a module
Explanation: 'from' is used to import specific items instead of the whole module.
4. Which method returns a list of all attributes in a module?
a) dir()
b) list()
c) help()
d) info()
Answer: a) dir()
Explanation: The dir() function returns all the attributes and methods of any object, including
modules.
5. How do you install a third-party module in Python?
a) install module
b) python get
c) pip install
d) import install
Answer: c) pip install
Explanation: 'pip install' is used to install packages from Python Package Index (PyPI).
6. Which module is used to generate random numbers in Python?
a) math
b) random
c) sys
d) os
Answer: b) random
Explanation: The 'random' module is used to generate pseudo-random numbers.
7. What does the __name__ variable do in a module?
a) It defines the module name
b) It tells whether a module is run as script or imported
c) It stores module version
d) It lists all functions
Answer: b) It tells whether a module is run as script or imported
Explanation: If __name__ == '__main__' checks if the script is executed directly or imported as a
module.
8. Which Python module is used to interact with the operating system?
a) system
b) os
c) file
d) subprocess
Answer: b) os
Explanation: The 'os' module provides a way of using operating system dependent functionality.
9. What is the output of '[Link](16)'?
a) 4
b) 8
c) 2
d) 16
Answer: a) 4
Explanation: The sqrt() function in the 'math' module returns the square root of a number.
10. Which module is used for date and time in Python?
a) datetime
b) time
c) date
d) calendar
Answer: a) datetime
Explanation: The 'datetime' module supplies classes for manipulating dates and times.
11. Dummy question 11?
a) Option 1
b) Option 2
c) Option 3
d) Option 4
Answer: a) Option 1
Explanation: This is an explanation for dummy question 11.
12. Dummy question 12?
a) Option 1
b) Option 2
c) Option 3
d) Option 4
Answer: a) Option 1
Explanation: This is an explanation for dummy question 12.
13. Dummy question 13?
a) Option 1
b) Option 2
c) Option 3
d) Option 4
Answer: a) Option 1
Explanation: This is an explanation for dummy question 13.
14. Dummy question 14?
a) Option 1
b) Option 2
c) Option 3
d) Option 4
Answer: a) Option 1
Explanation: This is an explanation for dummy question 14.
15. Dummy question 15?
a) Option 1
b) Option 2
c) Option 3
d) Option 4
Answer: a) Option 1
Explanation: This is an explanation for dummy question 15.
16. Dummy question 16?
a) Option 1
b) Option 2
c) Option 3
d) Option 4
Answer: a) Option 1
Explanation: This is an explanation for dummy question 16.
17. Dummy question 17?
a) Option 1
b) Option 2
c) Option 3
d) Option 4
Answer: a) Option 1
Explanation: This is an explanation for dummy question 17.
18. Dummy question 18?
a) Option 1
b) Option 2
c) Option 3
d) Option 4
Answer: a) Option 1
Explanation: This is an explanation for dummy question 18.
19. Dummy question 19?
a) Option 1
b) Option 2
c) Option 3
d) Option 4
Answer: a) Option 1
Explanation: This is an explanation for dummy question 19.
20. Dummy question 20?
a) Option 1
b) Option 2
c) Option 3
d) Option 4
Answer: a) Option 1
Explanation: This is an explanation for dummy question 20.