What is the difference between a tuple and a list in Python?
💡 Model Answer
In Python, a tuple is an immutable ordered sequence, while a list is a mutable ordered sequence. Because tuples cannot be modified after creation, they can be used as keys in dictionaries or elements of sets, whereas lists cannot. Tuples are defined using parentheses (e.g., (1, 2, 3)) and lists use brackets (e.g., [1, 2, 3]). The immutability of tuples makes them slightly faster for read‑only data and safer when you want to guarantee that the data will not change. Lists support methods like append, extend, pop, and remove, allowing dynamic modification. Tuples support only indexing, slicing, and concatenation. When you need a fixed collection of items that should not change, use a tuple; when you need to modify the collection, use a list. Example: a function that returns a pair of values might return a tuple to signal that the values are fixed. In contrast, a list is ideal for accumulating items in a loop. Both are indexed starting at 0 and support negative indices. The choice between them often comes down to whether mutability is required and whether the data will be used as a dictionary key or set element.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500