LearnFrenzy
Sign in Take a free test

Modules and Packages · Predict the Output · Question 2

from … import with an alias Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

What is the output of the following Python program?

main.py
from math import factorial as fact, gcd
print(fact(5), gcd(12, 18))
print("math" in dir(), "fact" in dir(), "factorial" in dir())
  • A 120 6 True True True
  • B 120 6 False True False Correct
  • C 120 6 True False True
  • D 24 6 False True False
Correct Answer: Option B

Only the names after import (here fact and gcd) are bound – not math, and not the original name factorial.

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