Bird
Raised Fist0

Why does Python allow triple-quoted strings to span multiple lines without using explicit newline characters?

hard🧠 Conceptual Q10 of Q15
Python - File Reading and Writing Strategies
Why does Python allow triple-quoted strings to span multiple lines without using explicit newline characters?
ABecause Python automatically adds \n at the end of each line
BBecause triple quotes convert all newlines to spaces
CBecause triple quotes preserve all whitespace including line breaks inside the string
DBecause triple quotes are only for comments, not strings
Step-by-Step Solution
Solution:
  1. Step 1: Understand triple-quoted string behavior

    Triple quotes keep all characters exactly as typed, including spaces and newlines.
  2. Step 2: Explain why explicit \n is not needed

    Because line breaks are preserved inside triple quotes, no need to add \n manually.
  3. Final Answer:

    Because triple quotes preserve all whitespace including line breaks inside the string -> Option C
  4. Quick Check:

    Triple quotes preserve whitespace and newlines [OK]
Quick Trick: Triple quotes keep text exactly as typed including new lines [OK]
Common Mistakes:
MISTAKES
  • Thinking Python adds \n automatically
  • Believing triple quotes remove new lines
  • Confusing triple quotes with comments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes