Courseiva
StringshardMultiple ChoiceObjective-mapped

PCAP String literal Practice Question

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])
```

Consider the following code:

print('"age": 30,')

⚠ Common exam trap

This question tests attention to detail: the string includes a trailing comma, which is easy to overlook if the candidate assumes it's a dictionary serialization.

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

"age": 30,

The code prints a literal string: "age": 30,. The double quotes are escaped within the single-quoted string, so they appear in the output. The trailing comma is part of the string, not a delimiter.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • "age": 30

    Why it's wrong here

    The line `"age": 30` without a trailing comma is not produced by `json.dumps()` when the object has more than one property. Within the pretty-printed output, every non-final key-value pair must be followed by a comma to remain valid JSON, so the actual third line is `"age": 30,`. Omitting that comma represents a hand-edited or truncated fragment rather than the exact output.

  • "age": 30,

    Why this is correct

    This is the exact third line of the pretty-printed JSON output when `indent=2` is used. The line begins with two spaces (the indentation for properties at the top level), then the key `"age"`, a colon and a space, and the value `30`, followed by a trailing comma. That comma is required because the `"city"` property still follows; this line matches the code's actual output verbatim.

  • "name": "Alice",

    Why it's wrong here

    The `"name": "Alice"` line is the second line of the pretty-printed output, immediately after the opening `{`, not the third. It is the first key-value pair in the object, so it does carry a trailing comma, but its position in the output is index 1, whereas the question asks for the line that appears at index 2. Selecting this option misidentifies the ordering of properties in the serialized JSON document.

  • "city": "New York"

    Why it's wrong here

    The `"city": "New York"` line is the fourth and final property line in the pretty-printed JSON output, appearing just before the closing `}`. As the last member of the object, it correctly has no trailing comma, which distinguishes it from the preceding `"age"` line. While it is a valid line of JSON output, it is not the third line, so it cannot be the correct answer.

About these practice questions

Courseiva writes every PCAP question from scratch — 169 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.