PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
Exhibit
Refer to the exhibit.
JSON policy file:
{
"name": "access-policy",
"rules": [
{"action": "permit", "src": "10.0.0.0/24", "dst": "0.0.0.0/0", "protocol": "tcp"},
{"action": "deny", "src": "0.0.0.0/0", "dst": "10.0.0.0/24", "protocol": "tcp"}
]
}A Python program loads this JSON and accesses the first rule's action. Which expression gives the string "permit"?
⚠ Common exam trap
Python Institute often tests the distinction between accessing the first element of a list (index 0) versus the second element (index 1), and between retrieving a dictionary value by key versus slicing or indexing a 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
✓
data["rules"][0]["action"]
It uses the correct indexing to access the first element of the 'rules' list (index 0) and then retrieves the value associated with the key 'action' from that dictionary. This yields the string 'permit' as stored in the JSON data.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
data["rules"][0]["action"]
Why this is correct
Subscripting `data["rules"]` returns the list, then `[0]` selects its first element — a dictionary — and `["action"]` retrieves that key's value, the string `"permit"`. This directly satisfies the stem's requirement to access the first rule's action field without iteration.
- ✗
data["rules"][0]["action"][:5]
Why it's wrong here
The slice [:5] returns only the first five characters, giving "permi" instead of the full string "permit". Slicing would be the correct approach if the task required a substring of the action value rather than the complete string.
- ✗
data["rules"][0]["action"][0]
Why it's wrong here
Indexing [0] on the string "permit" returns the single character "p", not the whole word. Character indexing would be correct if the question asked for the first letter of the action value rather than the entire string.
- ✗
data["rules"][1]["action"]
Why it's wrong here
Python lists are zero-indexed, so [1] returns the second rule, not the first, and would raise a KeyError or return the wrong action. Indexing at [1] would be correct if the question asked for the second rule's action rather than the first.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 482 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 →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP 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 PCEP exam.