Bird
0
0

What will be the output of this Python code on Raspberry Pi?

medium📝 Predict Output Q4 of 15
Raspberry Pi - Serial UART Communication
What will be the output of this Python code on Raspberry Pi?
import serial
ser = serial.Serial('/dev/ttyS0', baudrate=4800, timeout=1)
print(ser.baudrate)
A9600
BError: baudrate not set
C1
D4800
Step-by-Step Solution
Solution:
  1. Step 1: Understand the Serial object initialization

    The Serial object is created with baudrate=4800 and timeout=1 second.
  2. Step 2: Check what ser.baudrate returns

    ser.baudrate returns the baud rate value set, which is 4800 here.
  3. Final Answer:

    4800 -> Option D
  4. Quick Check:

    ser.baudrate = 4800 [OK]
Quick Trick: ser.baudrate returns the set baud rate value [OK]
Common Mistakes:
MISTAKES
  • Confusing baudrate with timeout value
  • Expecting print to show timeout
  • Assuming error if baudrate is set

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes