Bird
Raised Fist0

What is the correct way to import only the pi constant from the math module?

easy🧠 Conceptual Q1 of Q15
Python - Modules and Code Organization
What is the correct way to import only the pi constant from the math module?
Aimport math.pi
Bfrom math import pi
Cimport pi from math
Dfrom math import *
Step-by-Step Solution
Solution:
  1. Step 1: Understand Python import syntax

    To import a specific item, use from module import item.
  2. Step 2: Apply syntax to import pi from math

    The correct syntax is from math import pi.
  3. Final Answer:

    from math import pi -> Option B
  4. Quick Check:

    Import specific item = from module import item [OK]
Quick Trick: Use 'from module import item' to import specific parts [OK]
Common Mistakes:
MISTAKES
  • Using 'import math.pi' which is invalid syntax
  • Writing 'import pi from math' which is incorrect order
  • Using 'from math import *' imports everything, not specific

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes