Bird
0
0

Consider this __init__.py content:

medium📝 Predict Output Q5 of 15
Python - Modules and Code Organization
Consider this __init__.py content:
print("Package loaded")

What happens when you import this package?
AThe message is printed every time a module is imported
BNo message is printed
CThe message "Package loaded" is printed once
DAn error occurs because print is not allowed
Step-by-Step Solution
Solution:
  1. Step 1: Code execution in __init__.py

    Code in __init__.py runs once when the package is first imported.
  2. Step 2: Effect of print statement

    The print outputs the message once during import.
  3. Final Answer:

    The message "Package loaded" is printed once -> Option C
  4. Quick Check:

    Init code runs once on import [OK]
Quick Trick: Code in __init__.py runs once on first import [OK]
Common Mistakes:
  • Thinking print runs multiple times
  • Expecting no output
  • Assuming print causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes