Bird
Raised Fist0

Consider this code:

medium📝 Predict Output Q5 of Q15
Python - File Reading and Writing Strategies
Consider this code:
import sys
sys.stdout.write('Start')
sys.stdout.flush()
sys.stdout.write('End')

What will be the output?
AEndStart
BStart End
CStart End
DStartEnd
Step-by-Step Solution
Solution:
  1. Step 1: Analyze sys.stdout.write and flush

    sys.stdout.write('Start') writes 'Start' buffered. flush() forces immediate output of 'Start'.
  2. Step 2: Write 'End' after flush

    sys.stdout.write('End') writes 'End' immediately after 'Start' with no newline.
  3. Final Answer:

    StartEnd -> Option D
  4. Quick Check:

    Flush forces immediate output, no newline added [OK]
Quick Trick: Flush sends buffered output now, no newline added [OK]
Common Mistakes:
MISTAKES
  • Expecting newline after flush
  • Thinking flush clears buffer without output
  • Assuming output order changes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes