In Python, what is the difference between a list and a tuple?

Prepare for the TJR Bootcamp Test with flashcards and detailed questions. Get hints and explanations for each query. Ace your exam!

Multiple Choice

In Python, what is the difference between a list and a tuple?

Mutability matters for how you can change a collection after you create it. In Python, lists are mutable, so you can modify their contents after creation—replacing elements, appending, or removing items. For example, you can set a[0] = 9 or use a.append(4) to grow the list.

Tuples are immutable. Once a tuple is created, you can’t change its elements or add new ones. Trying to assign to an index or call a method that would modify it (like append) won’t work. If you want to “change” a tuple, you actually create a new one, for instance by concatenation or unpacking a new sequence.

Keep in mind that immutability applies to the container itself. If a tuple contains a mutable object, such as a list, that inner object can still be changed, even though the tuple’s structure can’t be altered. For example, a tuple holding a list can still mutate that inner list, but you can’t replace the inner list with a different object inside the tuple.

That’s why the correct characterization is that lists are mutable and tuples are immutable. Use lists for collections you plan to modify; use tuples for fixed groupings or as dictionary keys (when all elements are hashable) where you want to prevent in-place changes.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy