PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
What is the output of the following dictionary comprehension?
{x: x**2 for x in range(3)}⚠ Common exam trap
Python Institute often tests whether candidates remember that `range(3)` starts at 0, not 1, and that `0**2` equals 0, not an omitted or undefined value, causing many to drop the first key-value pair or miscalculate the square of 1.
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
✓
{0:0, 1:1, 2:4}
The dictionary comprehension `{x: x**2 for x in range(3)}` iterates over `x` values 0, 1, and 2 (from `range(3)`). For each `x`, it creates a key-value pair where the key is `x` and the value is `x**2` (x squared). This produces `{0: 0**2, 1: 1**2, 2: 2**2}`, which evaluates to `{0:0, 1:1, 2:4}`.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
{0:0, 1:1, 2:4}
Why this is correct
Correct.
- ✗
{0:1, 1:2, 2:3}
Why it's wrong here
Incorrect; values are squares.
- ✗
{0:0, 1:2, 2:4}
Why it's wrong here
Incorrect; 1 squared is 1, not 2.
- ✗
{1:1, 2:4}
Why it's wrong here
Incorrect; missing key 0.
Go deeper
Related to this question
About these practice questions
One of 498 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.