Which of the following is the correct way to import the LED class from gpiozero in Python?
easy📝 Syntax Q12 of 15
Raspberry Pi - gpiozero Library
Which of the following is the correct way to import the LED class from gpiozero in Python?
Aimport gpiozero.LED
Bimport LED from gpiozero
Cfrom gpiozero import led
Dfrom gpiozero import LED
Step-by-Step Solution
Solution:
Step 1: Recall Python import syntax
The correct syntax to import a class from a module is: from module import ClassName.
Step 2: Check options
from gpiozero import LED matches this syntax exactly with correct capitalization. import gpiozero.LED is invalid syntax, import LED from gpiozero reverses the import order (JavaScript syntax), and from gpiozero import led uses lowercase 'led' which is incorrect.
Final Answer:
from gpiozero import LED -> Option D
Quick Check:
Correct Python import syntax = from gpiozero import LED [OK]
Quick Trick:Use 'from module import Class' for classes [OK]
Common Mistakes:
Using wrong import syntax
Incorrect capitalization of class name
Trying to import with 'import Class from module'
Master "gpiozero Library" in Raspberry Pi
9 interactive learning modes - each teaches the same concept differently