Which of the following pair of symbols is used for multi-line strings in Python?

2026

Which of the following pair of symbols is used for multi-line strings in Python?

Answer: C. Pair of """ (Triple Quotes)Concept: A Python string literal is opened and closed by a matching pair of quote characters. What differs between the quoting styles is how the parser treats…

  1. A.

    Pair of '' (Single Quotes)

  2. B.

    Pair of # (Hash)

  3. C.

    Pair of """ (Triple Quotes)

  4. D.

    Pair of ! (Exclamation)

Attempted by 967 students.

Show answer & explanation

Correct answer: C

Concept: A Python string literal is opened and closed by a matching pair of quote characters. What differs between the quoting styles is how the parser treats a raw newline character typed between the opening and closing quotes: a single-quote or double-quote pair must close on the same physical line -- an unescaped newline inside it is a syntax error -- while a triple-quote pair (''' or """) keeps scanning until it reaches the matching triple-quote sequence, and any raw newline it meets along the way becomes part of the string's value instead of ending the literal.

Contrast: Checking each offered symbol pair against that rule:

  • A pair of single quotes ('...') must close on the same line it opens on; an unescaped newline between them raises a SyntaxError (the exact wording is version-dependent -- "EOL while scanning string literal" in older Python, "unterminated string literal" in newer versions), so representing more than one physical line needs an explicit \n escape or a backslash line-continuation.

  • A pair of hash symbols is not a string delimiter at all: a single # starts a comment that runs to the end of the physical line and is discarded by the parser, so it never produces a string value, single-line or multi-line.

  • A pair of triple quotes (''' or """) does not close at end-of-line: scanning continues past a raw (unescaped) newline, so that newline becomes part of the string's stored value instead of ending the literal or raising a syntax error.

  • A pair of exclamation marks plays no role in Python's string-delimiter syntax; '!' appears as part of the != comparison operator and as a conversion-flag prefix inside an f-string/format placeholder such as {value!r}, neither of which opens or closes a string literal.

s = """Line 1
Line 2"""
print(s)
# Line 1
# Line 2

Cross-check: Running the snippet above prints both physical lines from a single triple-quoted value, confirming the raw newline was retained rather than terminating the literal. Re-writing the same two-line source with a single-quote pair instead raises SyntaxError at the embedded newline, independently confirming that only the triple-quote pairing admits an unescaped multi-line literal.

Explore the full course: Hpsc Pgt Computer Science

Loading lesson…