Bird
0
0

You want to store multiple lines of text in a variable and then print it. Which approach correctly preserves the line breaks without using \n inside the string?

hard📝 Application Q9 of 15
Python - File Reading and Writing Strategies
You want to store multiple lines of text in a variable and then print it. Which approach correctly preserves the line breaks without using \n inside the string?
AUse single quotes and add \n manually
BUse triple quotes to assign the string to the variable
CUse double quotes and separate lines with commas
DUse single quotes and write all text on one line
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to preserve line breaks in strings

    Triple quotes allow multi-line strings with line breaks preserved automatically.
  2. Step 2: Identify correct method to store multi-line text

    Use triple quotes to assign the string to the variable uses triple quotes, so line breaks are kept without \n.
  3. Final Answer:

    Use triple quotes to assign the string to the variable -> Option B
  4. Quick Check:

    Triple quotes = Preserve line breaks without \n [OK]
Quick Trick: Triple quotes keep line breaks without \n [OK]
Common Mistakes:
  • Using single or double quotes without \n
  • Trying to separate lines with commas
  • Writing all text on one line

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes