Bird
0
0

You have a module file named utils.py with a function greet(). Which of these import statements will cause an error?

medium📝 Debug Q14 of 15
Python - Modules and Code Organization
You have a module file named utils.py with a function greet(). Which of these import statements will cause an error?
Aimport utils
Bimport utils.greet
Cfrom utils import greet
Dfrom utils import greet as hello
Step-by-Step Solution
Solution:
  1. Step 1: Understand Python import rules

    You can import a module or specific functions from it, but not a function as a submodule.
  2. Step 2: Check each option

    Options B, C, and D are valid. import utils.greet tries to import a function as a module, which causes ImportError.
  3. Final Answer:

    import utils.greet -> Option B
  4. Quick Check:

    Functions are imported, not as submodules [OK]
Quick Trick: Import modules or functions, not functions as modules [OK]
Common Mistakes:
  • Trying to import a function like a module
  • Confusing 'from' and 'import' usage
  • Using invalid aliases

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes