Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

Which FOUR of the following are valid ways to create a list with elements 1, 2, 3? (Choose four.)

⚠ Common exam trap

Python Institute often tests the distinction between the `list()` constructor requiring a single iterable argument versus the mistaken belief that it accepts multiple positional arguments, as in option D.

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

✓

[1, 2, 3,]

Option A, [1, 2, 3,], is correct because Python allows a trailing comma after the last element in a list literal, so it still produces the list [1, 2, 3]. Option B, list(range(1, 4)), is correct because range(1, 4) yields 1, 2, and 3 (the stop value 4 is exclusive), and list() converts that iterable into [1, 2, 3]. Option C, [1, 2, 3], is correct as the standard list literal syntax that directly creates the list [1, 2, 3]. Option E, list((1, 2, 3)), is correct because (1, 2, 3) is a tuple containing those three integers, and list() converts the tuple into the list [1, 2, 3]. Option D, list(1, 2, 3), is not valid because list() takes at most one argument (an iterable), so passing three separate integer arguments raises a TypeError.

Answer analysis

Option-by-option breakdown

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

  • ✓

    [1, 2, 3,]

    Why this is correct

    A trailing comma after the final element is permitted in Python list displays, so [1, 2, 3,] builds the list [1, 2, 3] correctly. The parser treats the comma as a separator before the closing bracket, making this a valid literal.

  • ✓

    list(range(1, 4))

    Why this is correct

    range(1, 4) generates the integers 1, 2 and 3, stopping before the exclusive end value 4. Passing that range object to list() materialises those elements into a new list, producing exactly [1, 2, 3] as required.

  • ✓

    [1, 2, 3]

    Why this is correct

    The list literal `[1, 2, 3]` directly constructs a list containing the three integer elements, satisfying the requirement to create a list with elements 1, 2, 3. Square brackets with comma-separated values are Python's fundamental list-display syntax, making this unambiguously valid.

  • ✗

    list(1, 2, 3)

    Why it's wrong here

    list() accepts at most one iterable argument, so list(1, 2, 3) raises TypeError because three positional arguments are supplied. The valid forms are list((1, 2, 3)) or list([1, 2, 3]), passing a single iterable. The literal [1, 2, 3] also creates the list directly.

  • ✓

    list((1, 2, 3))

    Why this is correct

    Invalid for this question. While list((1, 2, 3)) technically produces the list [1, 2, 3], it is a conversion from a tuple, not a direct list creation method. The question expects only literal or range-based constructions.

About these practice questions

This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.