PCEP Control Flow, Loops, Lists and Logic Practice Question
Which THREE of the following are valid ways to create a list with elements 10, 20, 30?
⚠ Common exam trap
In multi-select questions, carefully evaluate each option against the stem without reading in extra constraints. The question simply asks for valid ways to create a specific list; do not assume that a literal assignment is excluded unless explicitly stated. Be cautious about the number of correct answers: ensure you select all that apply, especially when the stem specifies a count.
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
✓
my_list = [x for x in (10,20,30)]
Option A is correct because a list comprehension iterating over the tuple (10,20,30) produces a new list [10, 20, 30]. Option B is correct because list((10, 20, 30)) converts the tuple into a list with those three elements. Option E is correct because a list literal [10, 20, 30] directly creates the desired list. Option C is invalid because list() accepts at most one iterable argument, so list(10, 20, 30) raises a TypeError. Option D is invalid because semicolons are not valid separators inside a Python list literal; elements must be comma-separated.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
my_list = [x for x in (10,20,30)]
Why this is correct
The list comprehension iterates over the tuple (10,20,30) and appends each element, producing a new list containing exactly those three values. It is a valid construction, though more verbose than a literal, and yields the required elements in order.
- ✓
my_list = list((10, 20, 30))
Why this is correct
The list() constructor accepts any iterable, including the tuple (10, 20, 30), converting it into a new list with those elements. This satisfies the stem's requirement for a valid list-creation method producing exactly 10, 20 and 30.
- ✗
my_list = list(10, 20, 30)
Why it's wrong here
list() accepts at most one iterable argument, so passing three separate integers raises a TypeError. It is tempting because list() does construct lists from iterables, and it would be correct as list((10, 20, 30)) or list([10, 20, 30]), where the elements arrive inside a single iterable.
- ✗
my_list = [10; 20; 30]
Why it's wrong here
Semicolons are not list element separators in Python; they terminate statements, so this raises a SyntaxError. Commas are required between list items. The square-bracket list literal itself is valid syntax, which makes the option tempting, but the punctuation inside is simply wrong for any Python list.
- ✓
my_list = [10, 20, 30]
Why this is correct
A list literal written with square brackets and comma-separated values directly constructs the list containing 10, 20 and 30. This is the most straightforward valid creation method, requiring no iteration or conversion, and produces exactly the required elements in order.
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.