Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

Which THREE of the following are valid ways to create a list in Python?

⚠ Common exam trap

The PCEP exam often tests the distinction between list literals (`[]`), tuple literals (`()`), and set literals (`{}`), trapping candidates who confuse the syntax for creating a list with that of other sequence or collection types.

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

✓

list((1, 2, 3))

Option A, list((1, 2, 3)), is correct because the list() constructor accepts any iterable — here a tuple — and returns a new list object [1, 2, 3]. Option B, [x for x in range(3)], is correct because a list comprehension is a valid literal-style expression that builds a list, producing [0, 1, 2]. Option C, [1, 2, 3], is correct because it is a direct list display (literal) using square brackets, which is the most basic way to create a list. Option D, (1, 2, 3), is not correct because parentheses with commas create a tuple, not a list. Option E, {1, 2, 3}, is not correct because curly braces create a set (or a dict if key-value pairs are used), not a list.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    list((1, 2, 3))

    Why this is correct

    Passing a tuple to the `list()` constructor iterates its elements and builds a new list, yielding `[1, 2, 3]`. This satisfies the stem's requirement for a valid list-creation method, since `list()` accepts any iterable, including tuples, strings and ranges, not just list literals.

  • ✓

    [x for x in range(3)]

    Why this is correct

    A list comprehension evaluates the expression for each item in the iterable, producing a new list object directly. Here `range(3)` yields 0, 1 and 2, so the result is `[0, 1, 2]`. This satisfies the stem's requirement for a valid list-creation method, since comprehensions always return a list.

  • ✓

    [1, 2, 3]

    Why this is correct

    Square brackets containing comma-separated values construct a list literal directly, which is the canonical syntax for creating a list in Python. This satisfies the question's requirement for a valid list-creation method, producing a mutable sequence of three integers without invoking any constructor or function call.

  • ✗

    (1, 2, 3)

    Why it's wrong here

    Parentheses with commas produce a tuple, which is immutable and cannot be modified after creation. It is tempting because the syntax closely mirrors list literals, but square brackets are what create a mutable list. Tuples suit fixed records where immutability is intended.

  • ✗

    {1, 2, 3}

    Why it's wrong here

    Curly braces with comma-separated values create a set, which stores unique unordered elements and rejects duplicates. It looks similar to list syntax, but sets cannot be indexed or hold duplicates. Sets are correct when membership testing or deduplication is required.

About these practice questions

One of 482 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 →

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.