Bird
Raised Fist0

You want to store a long message with multiple paragraphs in a variable and print it exactly as typed, including blank lines. Which is the best way to do this?

hard🚀 Application Q15 of Q15
Python - File Reading and Writing Strategies
You want to store a long message with multiple paragraphs in a variable and print it exactly as typed, including blank lines. Which is the best way to do this?
AConcatenate many single-line strings with + and \n
BUse triple quotes to write the message with blank lines inside
CUse single quotes and write all text in one line with \n
DUse multiple print statements for each line
Step-by-Step Solution
Solution:
  1. Step 1: Understand requirement for preserving formatting

    To keep multiple paragraphs and blank lines exactly as typed, the string must preserve line breaks and spaces.
  2. Step 2: Choose best method

    Triple quotes allow writing multi-line strings naturally, including blank lines, without needing \n or concatenation.
  3. Final Answer:

    Use triple quotes to write the message with blank lines inside -> Option B
  4. Quick Check:

    Triple quotes preserve formatting best for long multi-line text [OK]
Quick Trick: Triple quotes keep all line breaks and spaces as typed [OK]
Common Mistakes:
MISTAKES
  • Using concatenation makes code messy and error-prone
  • Forgetting to add \n for new lines in single quotes
  • Using multiple print statements loses single string storage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes