AllInfoHub Logo

AllInfoHub – MCQ Practice

Modules and Packages – Multiple Choice Questions (MCQs)

  1. 25. What is the purpose of a `requirements.txt` file in Python projects?

    • A. To list all the dependencies of the project
    • B. To store the project's source code
    • C. To define environment variables
    • D. To specify the Python version
  2. 26. How do you install all the dependencies listed in a `requirements.txt` file?

    • A. pip install -r requirements.txt
    • B. install -r requirements.txt
    • C. pip install requirements.txt -all
    • D. pip install requirements.txt
  3. 27. What is the output of `import sys; print(sys.path)`?

    • A. A list of strings specifying the search path for modules
    • B. The current Python version
    • C. The operating system name
    • D. A list of installed packages
  4. 28. What is the first directory listed in `sys.path` typically?

    • A. The directory where the script is being run
    • B. The Python installation directory
    • C. The current working directory
    • D. A temporary directory
  5. 29. What is the purpose of the `if __name__ == '__main__':` block in a Python module?

    • A. To define the main function of the module
    • B. To prevent code inside it from running when the module is imported
    • C. To specify the module's name
    • D. To document the module
  6. 30. If you run a Python file `my_script.py`, what will be the value of `__name__` within that script?

    • A. my_script'
    • B. __main__'
    • C. my_module'
    • D. __file__'
  7. 31. If you import `my_script.py` into another file, what will be the value of `__name__` within `my_script.py`?

    • A. my_script'
    • B. __main__'
    • C. my_module'
    • D. __file__'
  8. 32. What is the purpose of relative imports in Python packages?

    • A. To import modules within the same package without using the full package name
    • B. To import modules from a different Python installation
    • C. To import modules from the internet
    • D. To make imports faster
  9. 33. Which syntax is used for relative imports within a package?

    • A. `import .module`
    • B. `from ..package import module`
    • C. `from . import module`
    • D. All of the above
  10. 34. What does `from . import module_a` mean when used in a package?

    • A. Import `module_a` from the current directory
    • B. Import `module_a` from the parent directory
    • C. Import `module_a` from the same package
    • D. Import `module_a` from the standard library
  11. 35. What does `from .. import package_b` mean when used in a sub-package?

    • A. Import `package_b` from the current directory
    • B. Import `package_b` from the parent directory
    • C. Import `package_b` from the grandparent directory
    • D. Import `package_b` from the standard library
  12. 36. What is the purpose of the `__all__` variable in a Python module?

    • A. To specify which names should be exported when `from module import *` is used
    • B. To list all the functions in the module
    • C. To define private members of the module
    • D. To specify the module's dependencies