Bird
Raised Fist0

What will be the output of this code?

medium📝 Predict Output Q4 of Q15
Python - File Reading and Writing Strategies
What will be the output of this code?
print('Line1\nLine2\nLine3')
ALine1\nLine2\nLine3
BLine1 Line2 Line3
CLine1 Line2 Line3
DLine1\nLine2 Line3
Step-by-Step Solution
Solution:
  1. Step 1: Understand escape sequences in strings

    The \n inside a string creates a new line when printed.
  2. Step 2: Predict output of print statement

    Each \n causes the next text to appear on a new line, so output is three lines.
  3. Final Answer:

    Line1 Line2 Line3 -> Option B
  4. Quick Check:

    \n in string = New line in output [OK]
Quick Trick: Use \n inside strings to print multiple lines [OK]
Common Mistakes:
MISTAKES
  • Printing raw \n instead of new lines
  • Expecting spaces instead of new lines
  • Mixing escaped and unescaped newlines

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes