Bird
0
0

Which of the following is the correct way to import the GPIO library in Python on Raspberry Pi?

easy📝 Syntax Q12 of 15
Raspberry Pi - Platform
Which of the following is the correct way to import the GPIO library in Python on Raspberry Pi?
Aimport GPIO.RPi
Bimport RPi.GPIO as GPIO
Cfrom GPIO import RPi
Dimport raspberry.GPIO
Step-by-Step Solution
Solution:
  1. Step 1: Recall the standard import syntax for GPIO

    The correct import statement is import RPi.GPIO as GPIO to use GPIO functions easily.
  2. Step 2: Check other options for syntax errors

    The other options ('import GPIO.RPi', 'from GPIO import RPi', 'import raspberry.GPIO') do not follow Python import syntax or correct module names.
  3. Final Answer:

    import RPi.GPIO as GPIO -> Option B
  4. Quick Check:

    Standard GPIO import = import RPi.GPIO as GPIO [OK]
Quick Trick: Remember the exact module name: RPi.GPIO [OK]
Common Mistakes:
  • Swapping module and package names incorrectly
  • Using wrong import syntax
  • Assuming 'GPIO' alone is a module

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes