Foundations-of-Programming-Python practice question 5 of 10
Which Python data structure cannot be modified after creation?
Full set: 60 questionsA tuple is an immutable data structure in Python. Once a tuple is created, its contents cannot be altered. This means you cannot add, remove, or change its elements. Any attempt to modify a tuple, such as through item assignment (e.g., mytuple[0] = 'newvalue'), will result in a TypeError. This immutability makes tuples suitable for use as dictionary keys or in sets, where hashable, constant values are required.
A. A list is a mutable data structure; its elements can be changed, added, or removed after creation.
B. A dictionary is mutable; key-value pairs can be added, updated, or deleted.
D. A set is a mutable collection; elements can be added or removed.
1. Python Software Foundation. (2023). The Python Tutorial, Section 5.3, "Tuples and Sequences". Retrieved from https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences
2. MIT OpenCourseWare. (2016). 6.0001 Introduction to Computer Science and Programming in Python, Lecture 3 Notes, "Tuples". (This lecture explicitly defines tuples as immutable sequences).
3. Lutz, M. (2013). Learning Python, 5th Edition. O'Reilly Media, Chapter 9, "Tuples, Files, and Everything Else". (This chapter contrasts the immutability of tuples with the mutability of lists).
Keep practicing
Take the free Foundations-of-Programming-Python practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Foundations-of-Programming-Python practice questions
- Question 1Which components are required in every Python for loop?
- Question 2Which keyword moves a loop immediately to its subsequent iteration?
- Question 3A program needs to update all values in a list by adding 5 to each number. Which for loop…
- Question 4What must be consistent within a Python code block for the code to run without syntax err…
