Bird
0
0

Which of the following is the correct way to import the DistanceSensor class from the gpiozero library in Python?

easy📝 Syntax Q3 of 15
Raspberry Pi - gpiozero Library
Which of the following is the correct way to import the DistanceSensor class from the gpiozero library in Python?
Afrom gpiozero.DistanceSensor import *
Bimport DistanceSensor from gpiozero
Cfrom gpiozero import DistanceSensor
Dimport gpiozero.DistanceSensor
Step-by-Step Solution
Solution:
  1. Step 1: Recall Python import syntax

    The correct syntax to import a class from a module is: from module import ClassName.
  2. Step 2: Apply to gpiozero and DistanceSensor

    So, to import DistanceSensor from gpiozero, use: from gpiozero import DistanceSensor.
  3. Final Answer:

    from gpiozero import DistanceSensor -> Option C
  4. Quick Check:

    Python import class = from module import Class [OK]
Quick Trick: Use 'from module import Class' to import classes [OK]
Common Mistakes:
  • Using 'import Class from module' which is invalid syntax
  • Trying to import with wildcard from a class
  • Using dot notation in import statement incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes