Bird
0
0

What will be the output of this Python snippet reading GPS data? import serial ser = serial.Serial('/dev/serial0', 9600, timeout=1) line = ser.readline() print(type(line))

medium📝 Predict Output Q5 of 15
Raspberry Pi - Serial UART Communication
What will be the output of this Python snippet reading GPS data? import serial ser = serial.Serial('/dev/serial0', 9600, timeout=1) line = ser.readline() print(type(line))
A<class 'bytes'>
B<class 'str'>
C<class 'int'>
D<class 'list'>
Step-by-Step Solution
Solution:
  1. Step 1: Understand serial.readline() return type

    serial.readline() returns bytes, not string, until decoded.
  2. Step 2: Check print output

    Printing type(line) shows .
  3. Final Answer:

    <class 'bytes'> -> Option A
  4. Quick Check:

    serial.readline() returns bytes [OK]
Quick Trick: serial.readline() returns bytes, decode to get string [OK]
Common Mistakes:
MISTAKES
  • Assuming readline returns string
  • Expecting int or list type
  • Forgetting to decode bytes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes