Bird
0
0

What will be the output of this Python code?

medium📝 Predict Output Q4 of 15
Python - File Reading and Writing Strategies
What will be the output of this Python code?
import sys
sys.stdout.write('Hi')
print('There')
AHiThere
BHi There
CerehTiH
DThereHi
Step-by-Step Solution
Solution:
  1. Step 1: Understand sys.stdout.write

    sys.stdout.write('Hi') writes 'Hi' without a newline.
  2. Step 2: Understand print behavior

    print('There') writes 'There' followed by a newline.
  3. Step 3: Combine outputs

    Output concatenates to 'HiThere' plus a newline at the end.
  4. Final Answer:

    HiThere -> Option A
  5. Quick Check:

    sys.stdout.write does not add newline [OK]
Quick Trick: sys.stdout.write no newline; print adds newline [OK]
Common Mistakes:
  • Assuming sys.stdout.write adds newline
  • Expecting print to overwrite previous output
  • Confusing order of output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes