Bird
Raised Fist0

Which of the following is the correct way to write a string that spans multiple lines in Python?

easy🧠 Conceptual Q11 of Q15
Python - File Reading and Writing Strategies
Which of the following is the correct way to write a string that spans multiple lines in Python?
AUse double quotes but write all text in one line only
BUse single quotes and separate lines with commas
CUse triple quotes like <code>'''This is a\nmulti-line string'''</code>
DUse backslashes at the end of each line without quotes
Step-by-Step Solution
Solution:
  1. Step 1: Understand multi-line string syntax

    Python allows strings to span multiple lines using triple quotes (either ''' or """).
  2. Step 2: Check each option

    Use triple quotes like '''This is a\nmulti-line string''' correctly uses triple quotes to write a multi-line string. Other options misuse quotes or syntax.
  3. Final Answer:

    Use triple quotes like '''This is a\nmulti-line string''' -> Option C
  4. Quick Check:

    Triple quotes = multi-line string [OK]
Quick Trick: Remember: triple quotes let strings span multiple lines easily [OK]
Common Mistakes:
MISTAKES
  • Using single or double quotes without triple quotes
  • Trying to separate lines with commas inside quotes
  • Forgetting to close triple quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes