The answer is "age": 30, with the trailing comma included. This output occurs because the code explicitly constructs a string or dictionary-like representation that retains a comma after the final key-value pair, which is not the default behavior of Python’s standard dictionary print output. In Python, when you print a dictionary directly using print(), the built-in repr() omits a trailing comma after the last item, so seeing one indicates the code is manually formatting the output—often by joining key-value pairs with commas and appending one after the last pair. On the Certified Associate Python Programmer PCAP exam, this question tests your attention to detail in string formatting and your understanding of how Python’s dict representation differs from custom output. A common trap is assuming Python always omits the trailing comma, but the exam may present code that deliberately adds it. Memory tip: Python’s dict print is comma-separated but never comma-terminated—if you see a trailing comma, suspect manual construction.
PCAP Strings Practice Question
This PCAP practice question tests your understanding of strings. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
Exhibit
Refer to the exhibit.
```
# Code snippet
import json
data = {'name': 'Alice', 'age': 30, 'city': 'New York'}
json_str = json.dumps(data, indent=2)
print(json_str.split('\n')[2])
```
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
"age": 30,
The code likely uses a dictionary or JSON-like structure where the key-value pair "age": 30 is printed. Option B is correct because it shows the exact output with a trailing comma, which matches the format when printing a dictionary or JSON object with multiple key-value pairs, where the last pair may or may not have a trailing comma depending on the context. In Python, when printing a dictionary, the output includes commas between items, and the trailing comma after the last item is not present in standard dict representation, but if the code explicitly constructs a string with a trailing comma, B matches that.
Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
Read the scenario before looking for a memorised answer.
✗
"name": "Alice",
Why it's wrong here
That is the second line (index 1).
✗
"city": "New York"
Why it's wrong here
That is the fourth line (index 3).
Common exam traps
Common exam trap: answer the scenario, not the keyword
Python Institute often tests the candidate's ability to notice subtle formatting details like trailing commas in dictionary or JSON output, which can cause candidates to overlook the comma and choose an option that omits it.
Detailed technical explanation
How to think about this question
In Python, when you print a dictionary using print(), the output is formatted with curly braces, colons between keys and values, and commas between items. The trailing comma after the last item is not part of the standard dict representation; however, if the code uses json.dumps() with indentation or manually constructs a string, a trailing comma might appear. This question tests attention to detail in output formatting, especially when multiple key-value pairs are present, and the candidate must recognize that the output includes a comma after "age": 30 because there are more items in the dictionary.
KKey Concepts to Remember
Read the scenario before looking for a memorised answer.
Find the constraint that changes the correct option.
Eliminate answers that are true in general but not in this case.
TExam Day Tips
→Watch for words such as best, first, most likely and least administrative effort.
→Review why wrong options are wrong, not only why the correct option is correct.
Key takeaway
Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Real-world example
How this comes up in practice
A media company stores terabytes of video archives that are accessed once a year for audit purposes. Moving these objects to a cold storage tier (Azure Archive, S3 Glacier, or Google Nearline) costs a fraction of hot storage. Questions like this test whether you understand storage tiers, access frequency tradeoffs, and retrieval latency requirements.
What to study next
Got this wrong? Here's your next step.
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
Strings — This question tests Strings — Read the scenario before looking for a memorised answer..
What is the correct answer to this question?
The correct answer is: "age": 30, — The code likely uses a dictionary or JSON-like structure where the key-value pair "age": 30 is printed. Option B is correct because it shows the exact output with a trailing comma, which matches the format when printing a dictionary or JSON object with multiple key-value pairs, where the last pair may or may not have a trailing comma depending on the context. In Python, when printing a dictionary, the output includes commas between items, and the trailing comma after the last item is not present in standard dict representation, but if the code explicitly constructs a string with a trailing comma, B matches that.
What should I do if I get this PCAP question wrong?
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
What is the key concept behind this question?
Read the scenario before looking for a memorised answer.
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 →
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.
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.