Modules and Packages MCQ PRATICE QUESTIONS

Modules:

  1. Question: What is a module in Python?

    • a) A type of data structure
    • b) A collection of functions and variables
    • c) A built-in Python keyword
    • d) A Python package
  2. Question: Which statement is true regarding Python modules?

    • a) You can only import built-in modules.
    • b) Modules are reusable code files that can be imported into other Python scripts.
    • c) Modules can only contain functions, not variables.
    • d) Modules are exclusively used for defining classes.
      .
  3. Question: To use a module in your Python script, what keyword do you use?

    • a) module
    • b) import
    • c) use
    • d) from
  4. Question: Which of the following statements is true about the if __name__ == "__main__": block in a Python module?

    • a) It is used to define a function in the module.
    • b) It is executed only when the module is imported as a package.
    • c) It is executed only when the module is run as a standalone script.
    • d) It is used to create a new Python module.

Packages:

  1. Question: What is a Python package?

    • a) A special Python data type
    • b) A collection of related modules organized in directories
    • c) A built-in Python function
    • d) A Python module
  2. Question: Which of the following is the primary purpose of organizing modules into packages?

    • a) To make them harder to import
    • b) To create a single large module
    • c) To improve code organization and maintainability
    • d) To reduce the size of the modules
  3. Question: How do you import a specific module from a package in Python?

    • a) import package.module
    • b) from package import module
    • c) import module from package
    • d) from module import package
  4. Question: What file should be present in a package to indicate that it is a package and not just a regular directory?

    • a) package_init.py
    • b) package.info
    • c) package.py
    • d) package.config
      `
  5. Question: In a package, what is the purpose of the __init__.py file?

    • a) It contains package metadata.
    • b) It is required to make the package recognizable as a Python package.
    • c) It must contain the main module of the package.
    • d) It is optional and serves no specific purpose.
  6. Question: What is a subpackage in Python?

    • a) A package that contains only one module
    • b) A package that is a direct child of the main package
    • c) A package that is a subdirectory of another package
    • d) A package that is not allowed in Python
  1. b
  2. c
  3. b
  4. c
  5. b
  6. c
  7. b
  8. a
  9. b
  10. c
1 Like