Bird
0
0

Which of these code snippets correctly prints multiple lines using a multi-line string?

easy📝 Syntax Q12 of 15
Python - File Reading and Writing Strategies
Which of these code snippets correctly prints multiple lines using a multi-line string?
Aprint('''Line 1\nLine 2\nLine 3''')
Bprint('Line 1\n' + 'Line 2\n' + 'Line 3')
Cprint('Line 1\nLine 2\nLine 3')
Dprint('''Line 1 Line 2 Line 3''')
Step-by-Step Solution
Solution:
  1. Step 1: Understand how multi-line strings handle newlines

    Triple-quoted strings keep line breaks as typed, so actual newlines appear without \n escape sequences.
  2. Step 2: Analyze each option

    print('''Line 1 Line 2 Line 3''') uses triple quotes with actual newlines inside, so it prints three lines. print('''Line 1\nLine 2\nLine 3''') uses \n inside triple quotes, which prints literal \n, not new lines. Options B and D use single quotes with \n, which print new lines correctly, but are not multi-line strings.
  3. Final Answer:

    print('''Line 1 Line 2 Line 3''') -> Option D
  4. Quick Check:

    Triple quotes with real newlines print multiple lines [OK]
Quick Trick: Triple quotes keep line breaks as typed, no need for \n [OK]
Common Mistakes:
  • Using \n inside triple quotes expecting line breaks
  • Confusing escape sequences with actual newlines
  • Using single quotes for multi-line strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes