MCQs on Modules and Packages | Python programming

1. Importing Modules

  1. Which of the following is the correct syntax to import a module in Python?
    • a) import module
    • b) from module import *
    • c) include module
    • d) import module as alias
  2. What is the effect of the statement import math in Python?
    • a) It imports all functions of the math module into the global namespace
    • b) It imports the math module for use in the program
    • c) It imports only the square root function from math
    • d) It imports the math module and renames it as math
  3. What does the following Python code do?
    import math print(math.sqrt(16))
    • a) Prints the square root of 16
    • b) Prints 16
    • c) Prints math.sqrt(16)
    • d) Causes an error
  4. How do you import a specific function from a module in Python?
    • a) import function
    • b) from module import function
    • c) import module.function
    • d) import * from module
  5. Which of the following is the correct syntax for importing a module with an alias?
    • a) import math as m
    • b) import math to m
    • c) import math as m()
    • d) from math import m

2. Creating Modules

  1. What is the correct way to create a module in Python?
    • a) Define a function inside a .py file
    • b) Create a folder and add functions inside it
    • c) Write code inside a .py file
    • d) Use the module keyword
  2. Which of the following is true about Python modules?
    • a) A module is a collection of files
    • b) A module can only contain functions
    • c) A module is a single Python file containing related code
    • d) Modules cannot contain classes
  3. How can you use a function from a module you created named mymodule?
    • a) mymodule()
    • b) from mymodule import function_name
    • c) import mymodule.function_name
    • d) use mymodule.function_name
  4. If you have a file module.py with a function add(), how do you call it from another Python script?
    • a) module.add()
    • b) import module add()
    • c) from module import add
    • d) call module.add()
  5. How do you reload a Python module after making changes to it?
    • a) reload(module)
    • b) module.reload()
    • c) import module
    • d) from module import reload

3. Python Standard Library

  1. What is the Python Standard Library?
    • a) A collection of third-party packages
    • b) A set of modules included with Python
    • c) A set of functions built into the Python interpreter
    • d) A set of utilities for managing operating systems
  2. Which module from the Python Standard Library is used for file input/output operations?
    • a) os
    • b) sys
    • c) io
    • d) file
  3. Which module can you use to work with regular expressions in Python?
    • a) re
    • b) regex
    • c) expr
    • d) pattern
  4. What is the purpose of the math module in Python?
    • a) For manipulating strings
    • b) For performing mathematical operations
    • c) For working with dates and times
    • d) For working with lists
  5. Which of the following is a function available in the sys module?
    • a) sys.exit()
    • b) sys.math()
    • c) sys.time()
    • d) sys.print()

4. Built-in Modules (e.g., math, random, sys)

  1. Which of the following is true about the random module?
    • a) It provides functions for generating random numbers
    • b) It allows for random access to files
    • c) It manipulates random strings
    • d) It provides real-time clock functionality
  2. How do you generate a random integer between 1 and 10 using the random module?
    • a) random.randint(1, 10)
    • b) random.random(1, 10)
    • c) random.number(1, 10)
    • d) random.integer(1, 10)
  3. What is the purpose of the os module in Python?
    • a) For performing mathematical operations
    • b) For operating system-dependent functionality
    • c) For manipulating strings
    • d) For managing database connections
  4. Which module provides functions to interact with the operating system’s environment variables?
    • a) os
    • b) sys
    • c) path
    • d) env
  5. Which of the following is a function provided by the math module?
    • a) math.factorial()
    • b) math.random()
    • c) math.date()
    • d) math.input()

5. Installing External Packages using pip

  1. What does the pip tool do in Python?
    • a) Installs third-party libraries
    • b) Installs Python itself
    • c) Installs packages from the Python Standard Library
    • d) Installs Python modules from external websites
  2. How do you install a package named numpy using pip?
    • a) pip install numpy
    • b) pip add numpy
    • c) install numpy
    • d) python install numpy
  3. What command would you use to uninstall a package using pip?
    • a) pip remove package_name
    • b) pip uninstall package_name
    • c) pip delete package_name
    • d) pip erase package_name
  4. How can you list all installed packages using pip?
    • a) pip list
    • b) pip show
    • c) pip installed
    • d) pip info
  5. Which of the following is the correct way to upgrade an installed package using pip?
    • a) pip update package_name
    • b) pip upgrade package_name
    • c) pip install --upgrade package_name
    • d) pip install --update package_name

6. Package Creation and Structure

  1. What is the correct folder structure for creating a Python package?
    • a) One Python file in a folder
    • b) A folder with an __init__.py file and other modules
    • c) A folder with all Python files and no __init__.py
    • d) A folder with one module file
  2. What is the purpose of the __init__.py file in a Python package?
    • a) It defines the main function of the package
    • b) It marks the directory as a Python package
    • c) It contains the setup configuration
    • d) It manages external dependencies
  3. How do you import a module from a package named my_package?
    • a) import my_package.module_name
    • b) import module_name from my_package
    • c) from my_package import module_name
    • d) import module_name as my_package
  4. Which of the following is required to distribute a Python package?
    • a) __init__.py and setup.py
    • b) README.txt and LICENSE
    • c) install.py and setup.py
    • d) Only the Python module files
  5. What does the setup.py file do in a Python package?
    • a) Contains the documentation for the package
    • b) Contains instructions on how to install the package
    • c) Marks the package as a standalone application
    • d) Manages the dependencies of the package

Answers (Tabular Form)

Question No.Answer
1a
2b
3a
4b
5a
6c
7c
8b
9c
10a
11b
12c
13a
14b
15a
16a
17a
18b
19a
20a
21a
22a
23b
24a
25c
26b
27b
28c
29a
30b

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top