Courseiva
Question 259 of 498
Functions, Tuples, Dictionaries and ExceptionsmediumMultiple SelectObjective-mapped

When Can Tuples Be Used as Dictionary Keys in Python?

Which TWO of the following statements about tuples in Python are true?

Quick Answer

The answer is that tuples can be used as dictionary keys only when all of their elements are hashable. This is because tuples themselves are immutable sequences, but their hash value is computed from the hash values of their constituent elements; if any element is unhashable—such as a list or another mutable object—the tuple becomes unhashable and cannot serve as a dictionary key. On the Certified Entry-Level Python Programmer PCEP exam, this concept tests your understanding of the interplay between immutability and hashability, often appearing in multiple-choice questions that present tuples containing lists as a common trap. A frequent trick is assuming all tuples are automatically hashable, but the key rule is that hashability depends on the elements, not just the tuple type. For a quick memory tip, remember: "A tuple is only as hashable as its contents—if it holds a list, it cannot be keyed."

⚠ Common exam trap

Python Institute often tests the misconception that 'tuples are immutable' automatically means 'tuples are always hashable' or 'tuples can only contain immutable objects,' leading candidates to incorrectly select options A or 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

Tuples can be used as dictionary keys if all elements are hashable.

Tuples can be used as dictionary keys only when all of their elements are hashable. Since tuples themselves are immutable, their hash value depends on the hash values of their elements; if any element is unhashable (e.g., a list), the tuple itself becomes unhashable and cannot be used as a key.

Answer analysis

Option-by-option breakdown

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

  • Tuples are always hashable.

    Why it's wrong here

    Tuples containing unhashable items are not hashable.

  • Tuples can be used as dictionary keys if all elements are hashable.

    Why this is correct

    A tuple is hashable if all its items are hashable.

  • Tuples do not support indexing.

    Why it's wrong here

    Tuples support indexing like lists.

  • Tuples can only contain immutable objects.

    Why it's wrong here

    They can contain mutable objects like lists.

  • Tuples are immutable sequences.

    Why this is correct

    Correct: tuples cannot be changed after creation.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on PCEP

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

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

easy
  • A.The code raises a TypeError.
  • B.The tuple is converted to a list automatically.
  • C.The first element is modified successfully.
  • D.The code raises a ValueError.

Why A: 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.

Last reviewed: Jun 30, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.