LearnFrenzy
Sign in Take a free test

Modules and Packages · Predict the Output · Question 4

Importing the same module twice Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

What is the output of the following Python program?

main.py
import sys
import math
import math as again
print(again is math, "math" in sys.modules, sys.modules["math"] is math)
  • A False True False
  • B True False True
  • C False False False
  • D True True True Correct
Correct Answer: Option D

Every import of math returns the single module object cached in sys.modules.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links