PCAP Strings Practice Question
Which two of the following are valid ways to create a multiline string in Python source code? (Choose two.)
⚠ Common exam trap
The PCAP exam often tests the distinction between a string that contains a newline character (via \n) and a string that is physically multiline in source code, tricking candidates into thinking any string with \n is 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\nLine2"""
Triple-quoted strings ("""...""") in Python allow multiline content directly in source code, including explicit escape sequences like \n. The triple quotes preserve the string as a single object spanning multiple lines, making it a valid multiline string.
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\nLine2"
Why it's wrong here
The escape sequence \n does make the runtime string contain a line break, but the source code itself is a single physical line. Python does not treat a single-quoted or double-quoted literal with escapes as a multiline string literal; it is simply a one-line literal encoding a newline character.
- ✗
s = 'Line1' 'Line2'
Why it's wrong here
This uses implicit adjacent-string concatenation, a compile-time feature that merges two separate literals into one value. Since no newline is present inside either literal or between them, the result is the single-line string 'Line1Line2' — there is no line break and no multiline literal syntax.
- ✓
s = """Line1\nLine2"""
Why this is correct
Triple double quotes define a multiline string literal: the opening and closing delimiters may be on different physical lines, and any raw line breaks inside become part of the string. Including \n adds an explicit line break as well; this is one of the two accepted forms for multiline literals in Python.
- ✓
s = '''Line1\nLine2'''
Why this is correct
Triple single quotes are the other valid delimiter for multiline literals. The syntax is exactly as permissive as triple double quotes: it can span physical lines, and the escape \n is interpreted as a newline character, making this a correct way to build a multiline string.
- ✗
s = 'Line1\nLine2'
Why it's wrong here
A single-quoted literal cannot contain a raw physical line break, and using \n only inserts a newline character into the value at runtime. This is a valid escaped string, but it is not a multiline literal because the source code occupies exactly one line, just with a different quote style than the double-quoted version.
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
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.