Courseiva
Functions, Tuples, Dictionaries and ExceptionseasyMultiple ChoiceObjective-mapped

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A developer writes a function that takes a tuple as an argument and tries to modify an element inside the tuple. What happens?

⚠ Common exam trap

Python Institute often tests the distinction between `TypeError` and `ValueError` — the trap here is that candidates may confuse an operation that is not allowed (TypeError) with an operation that receives an invalid value (ValueError).

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

The code raises a TypeError.

Tuples in Python are immutable, meaning their elements cannot be changed after creation. Attempting to modify an element (e.g., `my_tuple[0] = 5`) raises a `TypeError` because the tuple object does not support item assignment. This is a fundamental property of the tuple data type.

Answer analysis

Option-by-option breakdown

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

  • The code raises a TypeError.

    Why this is correct

    Tuples do not support item assignment.

  • The tuple is converted to a list automatically.

    Why it's wrong here

    No automatic conversion.

  • The first element is modified successfully.

    Why it's wrong here

    Tuples are immutable.

  • The code raises a ValueError.

    Why it's wrong here

    The error type is TypeError.

About these practice questions

This PCEP question is part of Courseiva's 498-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.