Question 483 of 498
PCEP Control Flow, Loops, Lists and Logic Practice Question
A developer writes: result = [x**2 for x in range(10) if x % 2 == 0]. What does this code produce?
⚠ Common exam trap
The trap here is that candidates may overlook the `if` filter and think the comprehension squares all numbers 0–9, or they may confuse list comprehensions with generator expressions, which use parentheses instead of square brackets.
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
✓
A list containing [0, 4, 16, 36, 64]
The code uses a list comprehension with a conditional filter: `[x**2 for x in range(10) if x % 2 == 0]`. It iterates over numbers 0 through 9, keeps only even numbers (those where `x % 2 == 0`), squares each, and collects the results into a list. The resulting list is `[0, 4, 16, 36, 64]`, which are the squares of the even numbers 0, 2, 4, 6, and 8.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
A list of even numbers squared
Why it's wrong here
This is true but the specific list is [0,4,16,36,64]; however the answer C is more precise.
- ✗
A generator object
Why it's wrong here
List comprehension produces a list, not a generator.
- ✗
A list of squares of all numbers from 0 to 9
Why it's wrong here
The if clause filters only even numbers.
- ✓
A list containing [0, 4, 16, 36, 64]
Why this is correct
Correct: squares of even numbers 0,2,4,6,8.
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 →
Same concept, more angles
2 more ways this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Which THREE of the following are correct ways to create a list containing the numbers 1, 2, 3? (Choose three.)
hard- ✓ A.[x for x in range(1,4)]
- B.(1, 2, 3)
- ✓ C.list((1, 2, 3))
- ✓ D.[1, 2, 3]
- E.{1, 2, 3}
Why A: It uses a list comprehension with `range(1,4)`, which generates the numbers 1, 2, and 3 and collects them into a new list. This is a concise and valid Python syntax for creating a list from an iterable.
Variation 2. Which THREE of the following are valid ways to create a list with elements 1, 2, 3? (Choose Three)
hard- ✓ A.[1,2,3]
- ✓ B.list(range(1,4))
- C.(1,2,3)
- ✓ D.[x for x in range(1,4)]
- E.{1,2,3}
Why A: It uses the literal list syntax with square brackets and commas to directly create a list containing the integers 1, 2, and 3. This is the most straightforward and explicit way to define a list in Python.
Last reviewed: Jun 25, 2026
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.
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.