Bird
Raised Fist0

You want to import the Counter class from collections and the sqrt function from math in one line. Which is correct?

hard🚀 Application Q9 of Q15
Python - Modules and Code Organization
You want to import the Counter class from collections and the sqrt function from math in one line. Which is correct?
Afrom collections import Counter; from math import sqrt
Bfrom collections import Counter, sqrt
Cfrom collections import Counter from math import sqrt
Dimport collections.Counter, math.sqrt
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple imports from different modules

    You cannot import from two modules in one from-import statement.
  2. Step 2: Use two separate import statements separated by semicolon

    Use from collections import Counter; from math import sqrt.
  3. Final Answer:

    from collections import Counter; from math import sqrt -> Option A
  4. Quick Check:

    Separate imports by semicolon for multiple modules [OK]
Quick Trick: Use separate from-import statements for different modules [OK]
Common Mistakes:
MISTAKES
  • Trying to import items from different modules in one statement
  • Using commas to separate imports from different modules
  • Using dot notation inside import statement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes