Which of the following is immutable data type in Python?

2023

Which of the following is immutable data type in Python?

  1. A.

    Set / Set

  2. B.

    List / List

  3. C.

    Tuple / Tuple

  4. D.

    Dictionary / Dictionary

Attempted by 2170 students.

Show answer & explanation

Correct answer: C

Correct answer: Tuple

Explanation:

  • What immutable means: an immutable object cannot be changed after it is created.

  • Why tuple is immutable: you cannot assign to a tuple element or add/remove elements. For example, trying to do t[0] = value will raise a TypeError.

  • Contrast with mutable types: list, set, and dictionary can be modified after creation using operations like append(), add(), pop(), update(), or assignment to indices/keys.

  • Immutable alternatives: frozenset is an immutable set; strings and numeric types are also immutable.

  • When to use tuple: for fixed collections of items, for grouping values that should not change, and when you need a hashable sequence (e.g., as a dictionary key).

Explore the full course: Rssb Senior Computer Instructor