Courseiva

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

What happens when you try to modify a tuple?

t = (1, 2, 3) t[0] = 0

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 TypeError is raised

Tuples are immutable, so trying to assign to an index 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.

  • ✓

    A TypeError is raised

    Why this is correct

    Tuples are immutable, so item assignment such as t[0] = 0 is unsupported. Python raises a TypeError at runtime rather than silently ignoring the change, which is the defined behaviour for attempting to modify tuple elements.

  • ✗

    A IndexError is raised

    Why it's wrong here

    Assigning to a tuple index raises TypeError, not IndexError, because index 0 exists and is valid. IndexError arises only when the index is out of range. It tempts because both errors concern indexing, but the failure here is the immutability of the tuple, not a missing element.

  • ✗

    The tuple becomes (0, 2, 3)

    Why it's wrong here

    The tuple cannot become (0, 2, 3); immutability means no item assignment is permitted, so a TypeError is raised and the original tuple is unchanged. It tempts because lists behave exactly this way, and the syntax looks identical, but tuples lack the mutation support lists provide.

  • ✗

    The code runs without error

    Why it's wrong here

    Tuples are immutable, so item assignment raises TypeError before any change occurs. The code cannot run without error. It tempts because tuples support indexing for reads, so learners assume writes behave the same way; the immutability constraint blocks assignment to an existing index.

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.