Courseiva

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A developer wants to create a tuple containing a single integer value 5. Which code snippet correctly creates such a tuple?

⚠ Common exam trap

The PCEP exam often tests the misconception that parentheses alone create a tuple, leading candidates to choose `(5)` instead of `(5,)`.

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

✓

t = (5,)

A tuple with a single element requires a trailing comma to disambiguate it from a parenthesized expression. Without the comma, Python treats parentheses as grouping operators, not tuple syntax. Thus, `(5,)` creates a tuple containing the integer 5, while `(5)` is just the integer 5.

Answer analysis

Option-by-option breakdown

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

  • ✗

    t = [5]

    Why it's wrong here

    Square brackets build a list, so t = [5] yields a mutable list rather than a tuple. It is tempting because both are ordered sequences, but the requirement specifies a tuple. Tuple syntax uses parentheses with a trailing comma for a single element: t = (5,).

  • ✗

    t = (5)

    Why it's wrong here

    t = (5) evaluates the parenthesised expression to the integer 5, so t holds an int, not a tuple. Parentheses group here rather than construct. It is tempting because multi-element tuples accept parentheses, but a one-element tuple needs the trailing comma: t = (5,).

  • ✗

    t = 5

    Why it's wrong here

    Assigning t = 5 binds an int, not a tuple; parentheses, not bare assignment, create tuple literals. It is tempting because tuples are often written without brackets, but that shorthand applies only to multi-element tuples. A single-element tuple requires a trailing comma: t = (5,).

  • ✓

    t = (5,)

    Why this is correct

    The trailing comma is what makes this a tuple rather than an integer in parentheses. Python's grammar requires that comma to disambiguate a single-element tuple from a grouped expression, so `(5,)` satisfies the stem's constraint of holding exactly one integer, 5. Without it, `t = (5)` binds an int.

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 →

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.