AllInfoHub Logo

AllInfoHub – MCQ Practice

Modules and Packages – Multiple Choice Questions (MCQs)

  1. 1. What is a module in Python?

    • A. A small program
    • B. A single file containing Python code
    • C. A collection of related packages
    • D. A keyword used for loops
  2. 2. Which keyword is used to import a module in Python?

    • A. import
    • B. include
    • C. using
    • D. require
  3. 3. How do you import a module named 'math' in Python?

    • A. import math
    • B. include math
    • C. using math
    • D. require math
  4. 4. Once a module 'math' is imported, how do you access the square root function?

    • A. math.sqrt()
    • B. sqrt()
    • C. math->sqrt()
    • D. math:sqrt()
  5. 5. How do you import a specific function 'sqrt' from the 'math' module?

    • A. import sqrt from math
    • B. from math import sqrt
    • C. import math.sqrt
    • D. include math.sqrt
  6. 6. If you import `from math import sqrt`, how do you call the square root function?

    • A. math.sqrt()
    • B. sqrt()
    • C. math->sqrt()
    • D. math:sqrt()
  7. 7. How do you import all names from a module 'math'?

    • A. import * from math
    • B. from math import *
    • C. import math.*
    • D. include math.*
  8. 8. What is the potential drawback of using `from module import *`?

    • A. It can lead to namespace collisions
    • B. It makes the code run slower
    • C. It only imports built-in functions
    • D. It requires more memory
  9. 9. How do you import a module 'my_module' with an alias 'mm'?

    • A. import my_module as mm
    • B. import mm from my_module
    • C. alias my_module as mm
    • D. import my_module(mm)
  10. 10. If you import `import my_module as mm`, how do you access a function 'my_function' from it?

    • A. my_module.my_function()
    • B. mm.my_function()
    • C. my_function()
    • D. mm->my_function()
  11. 11. What is a package in Python?

    • A. A single file containing Python code
    • B. A directory containing Python module file(s) and an optional `__init__.py` file
    • C. A collection of unrelated modules
    • D. A keyword used for defining classes
  12. 12. What is the purpose of the `__init__.py` file in a Python package?

    • A. To mark the directory as a regular package
    • B. To define global variables for the package
    • C. To automatically execute code when the package is imported
    • D. All of the above