Question 243 of 169
PCAP Strings Practice Question
Which THREE are valid ways to create a multiline string in Python?
⚠ Common exam trap
Python Institute often tests the distinction between physical line continuation (backslash) and actual multiline string creation (triple quotes or implicit concatenation with `\n`), trapping candidates who think a backslash at line end produces a multiline string.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
s = ('Line1\n' 'Line2')
Options A, B, and C are all valid ways to create a multiline string in Python. Option A uses implicit string concatenation within parentheses; the `\n` escape sequence inserts a newline, resulting in a multiline string. Option B uses triple double quotes to span multiple lines physically, preserving line breaks. Option C uses triple single quotes, which work identically to triple double quotes for multiline strings. Option D uses a backslash for line continuation, which does not insert a newline into the string—it just continues the literal on the next line, so the result is a single-line string without a newline. Option E causes a syntax error because a single-quoted string literal cannot span multiple lines without a continuation character.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
s = ('Line1\n' 'Line2')
Why this is correct
This is correct because Python implicitly concatenates adjacent string literals at compile time. The expression ('Line1\n' 'Line2') produces the single string 'Line1\nLine2', where \n is a single escape character representing a line break. When printed, the result appears on two lines, so it is a valid multiline string. The parentheses are not required but help break long lines for readability.
- ✓
s = """Line1 Line2"""
Why this is correct
This is correct because triple double quotes, like triple single quotes, let a string span multiple physical source lines while preserving the embedded line breaks exactly as typed. The resulting string contains a newline character at the end of the first line, so it behaves as a genuine multiline string. This syntax is the standard choice for docstrings and is also convenient for writing SQL or long formatted text blocks in code.
- ✓
s = '''Line1 Line2'''
Why this is correct
This is correct because triple single quotes allow a string literal to contain literal newline characters, meaning the physical line break between Line1 and Line2 is preserved as part of the string value. It is equivalent to writing 'Line1\nLine2' but is more readable when the string is long. Additionally, triple single quotes permit embedded single quotes without escaping, giving it flexibility for multiline text.
- ✗
s = "Line1\ Line2"
Why it's wrong here
This is incorrect because the backslash at the end of the first line is a line-continuation escape, not a newline-inserting character. It tells Python to ignore the physical line boundary and continue parsing the same logical string literal on the next line, so the resulting value is 'Line1Line2'—a single-line string with no newline. Although the source code occupies two physical lines, the string itself contains no line break, so it is not a multiline string.
- ✗
s = 'Line1 Line2'
Why it's wrong here
This is invalid because a single-quoted string literal cannot span multiple physical lines in Python; the quote after Line1 closes the string, and Line2 is parsed as a separate, unexpected token, causing a SyntaxError. Raw newlines inside a standard string literal are forbidden—they must be escaped as \n or the string must use triple quotes. Thus this source code does not compile.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 30, 2026
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.