PCAP Strings Practice Question
Consider the following code: result = ' '.join(['a', 'b', 'c'])
print(repr(result))
What is the output?
⚠ Common exam trap
Python Institute often tests the difference between `str()` and `repr()`, and the trap here is that candidates forget `repr()` adds quotes to the string output, leading them to choose the unquoted version (Option D) or the wrong quote style (Option B).
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
✓
'a b c'
The `join()` method concatenates the list elements with a space separator, producing the string `'a b c'`. The `repr()` function returns a string representation that includes quotes, so the output is `'a b c'` (with single quotes). Option C is correct because it matches the exact output of `print(repr(result))`.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
['a', 'b', 'c']
Why it's wrong here
This is a list literal, not the string produced by str.join(). The join() method always returns a string, concatenating the elements in the iterable with the separator string, so the spaces between 'a', 'b', and 'c' are characters inside one string, not separators between list items. The presence of commas and brackets indicates a list object, which would not be the result of calling join() on a string.
- ✗
"a b c"
Why it's wrong here
Although the double-quoted version represents the same string value as the correct answer, Python's repr() function displays strings using single quotes by default when the string does not contain a single quote itself. Since 'a b c' has no embedded single quotes, repr() would emit 'a b c', not "a b c". Double quotes are only chosen by repr() for a string that already contains a single quote character, which is not the case here.
- ✓
'a b c'
Why this is correct
This is the exact string returned by the join() operation: a single string containing the characters 'a', a space, 'b', another space, and 'c'. In an interactive Python session or when using repr(), the result is shown with single quotes around it to clearly delimit it as a textual string object. The single quotes are part of the representation, not the actual data, and they confirm the value is a str, not a list or other container.
- ✗
a b c
Why it's wrong here
Without quotes, a b c is not a valid representation of any Python object; it would be parsed as a sequence of three separate names separated by spaces, which is not legal Python syntax and cannot be a value in a REPL context. repr() always includes string delimiters so that the output can be unambiguously recognized as a string, distinguishing it from a variable name or an identifier. Therefore, the unquoted form is missing the necessary quoting and is not what repr(result) would produce.
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.