Courseiva
Data Types, Variables, Basic I/O and OperatorshardMultiple ChoiceObjective-mapped

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

    Correct: accesses first rule's action value.

  • data["rules"][0]["action"][:5]

    Why it's wrong here

    This gets first 5 characters 'permi'.

  • data["rules"][0]["action"][0]

    Why it's wrong here

    This gets first character of 'permit' = 'p'.

  • data["rules"][1]["action"]

    Why it's wrong here

    This gets the second rule's action ("deny").

About these practice questions

Courseiva writes every PCEP question from scratch — 498 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 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.