List vs tuple in Python: a list can change, and a tuple cannot have its items replaced after it is made. Both keep items in order and allow duplicates. Choose a list for items that grow or change. Choose a tuple for a small fixed group.
The formal word for "can change" is mutable. The word for "cannot change" is immutable.
Verdict: list vs tuple at a glance
| Point | List | Tuple |
|---|---|---|
| Example | [10, 20] |
(10, 20) |
| Ordered | Yes | Yes |
| Allows duplicates | Yes | Yes |
| Use an index | Yes | Yes |
| Replace an item | Yes | No |
| Add or remove items | Yes | No |
| Can be a dictionary key | No | Yes, if all its items are hashable |
| Good fit | Cart items, marks, tasks | Coordinates, fixed records |
Tuples can save a little memory and time, but the main difference is the promise you make. A list says "this can change". A tuple says "keep this fixed".
Hashable means Python can turn a value into a fixed number that it uses to find a dictionary key or set item. Numbers and strings are hashable. Lists are not.
Create and change them
This is a list:
marks = [70, 80, 90]
marks[0] = 75
marks.append(85)
print(marks)
The output is:
[75, 80, 90, 85]
The same list changed in two ways. We replaced its first item and added a new item.
Now use a tuple:
point = (10, 20)
print(point[0])
This prints 10. You can read by index, just like a list. But changing an item raises a TypeError:
point = (10, 20)
point[0] = 15
You can make a new tuple with different values. The first tuple stays the same:
point = (10, 20)
new_point = (15, point[1])
print(point)
print(new_point)
The output is:
(10, 20)
(15, 20)
Common mistake: A common mistake beginners make is to write
(5)and expect a tuple. It is only the number 5. Write(5,)for a one-item tuple.
Methods and everyday operations
Lists have many methods that change them:
| List method | What it does |
|---|---|
append(x) |
Adds one item at the end |
extend(items) |
Adds items from another collection |
insert(i, x) |
Adds at an index |
pop() |
Removes and returns the last item |
remove(x) |
Removes the first matching item |
sort() |
Sorts this list |
Tuples have two main methods:
count(x)counts matching items.index(x)finds the first matching position.
Both types work with len, in, loops and slices. For example:
colors = ("red", "blue", "red")
print(colors.count("red"))
print("blue" in colors)
print(colors[0:2])
The output is:
2
True
('red', 'blue')
To sort a tuple, use sorted(). It returns a list, so convert it back if you need a tuple:
nums = (3, 1, 2)
ordered = tuple(sorted(nums))
print(ordered)
This prints (1, 2, 3). The old tuple stays the same.
A tuple may hold an item that changes
A tuple's slots are fixed. An item inside one slot may still be mutable:
student = ("Asha", [80, 90])
student[1].append(85)
print(student)
Output:
('Asha', [80, 90, 85])
You did not replace the list in slot 1. You changed the list that was already there. If you try student[1] = [], Python raises a TypeError.
Because this tuple holds a list, it cannot be a dictionary key or a set item. A tuple made only of hashable items can be:
seat_owner = {
(1, 4): "Asha",
(2, 7): "Ravi",
}
print(seat_owner[(1, 4)])
This prints Asha. The row and seat number together make one key.
Passing and returning data
Assigning a list to a second name does not copy the list:
first = [1, 2]
second = first
second.append(3)
print(first)
This prints [1, 2, 3], because both names point to the same list. Use second = first.copy() to make a separate outer list. Nested lists inside it are still shared.
Functions often return tuples when they give back several values:
def low_and_high(nums):
return min(nums), max(nums)
low, high = low_and_high([8, 3, 10])
print(low, high)
This prints 3 10. The comma in the return makes a tuple. The next line splits it into two names, which is called unpacking.
Pro tip: Use a tuple when each position has a clear meaning, such as
(width, height). If you need names instead of positions, a dictionary or dataclass may be easier to read.
List vs tuple vs set in Python
A set is a group of unique items. It is useful for checking if something is present and for removing duplicates.
| Need | List | Tuple | Set |
|---|---|---|---|
| Keep order by position | Yes | Yes | No |
| Change the group | Yes | No | Yes |
| Keep duplicates | Yes | Yes | No |
| Use an index | Yes | Yes | No |
| Average cost to find a value | O(n) | O(n) | O(1) |
tags = ["python", "sql", "python"]
unique_tags = set(tags)
print(len(unique_tags))
This prints 2. Do not expect the set to keep the list's order. A set's items must be hashable, so a list cannot be one of them.
In a tiny group, the speed difference will not matter. For many checks against a large group, a set is usually the right fit. A frozenset is a set that cannot be changed.
So the short list vs tuple vs set rule is: a list for order that changes, a tuple for order that stays fixed, and a set for unique items with quick checks.
List vs tuple vs set vs dictionary in Python
A dictionary stores a key with each value. It answers "what value belongs to this key?" rather than "what item is at this position?"
| Type | Example | Main use | Duplicate rule |
|---|---|---|---|
| List | [1, 2] |
Ordered items that can change | Duplicates allowed |
| Tuple | (1, 2) |
Fixed ordered group | Duplicates allowed |
| Set | {1, 2} |
Unique items | Duplicates removed |
| Dictionary | {"id": 1} |
Key and value lookup | Keys are unique |
Values in a dictionary may be repeated. A new value given to an existing key replaces the old value.
student = {"name": "Asha", "marks": 85}
student["marks"] = 90
print(student["marks"])
This prints 90.
An empty pair of braces, {}, makes a dictionary. Write set() to make an empty set. Many list vs tuple vs set vs dictionary test questions check this point.
See Python dictionary for its methods and examples. For making lists in one line, use Python list comprehension.
Speed and memory: what should you say?
Reading an item by position is O(1) for both. Searching for a value is O(n), because Python may check many items. Adding at the end of a list is O(1) on average. Adding at the front takes O(n), because items must shift.
A tuple may use less memory than a list with the same items. A list needs some extra details because it can grow. The real gap varies by Python version and code. Measure a slow program before you change types for speed.
If you need a queue, do not repeatedly remove the first list item. Use collections.deque. Stack vs queue shows why.
Choose a list if / Choose a tuple if
Choose a list if:
- The number of items may change.
- You need to sort or edit the same collection.
- The items form one growing group.
Choose a tuple if:
- The positions have fixed meanings.
- You do not want items to be replaced by accident.
- You need an ordered group as a dictionary key.
Choose a set for unique items. Choose a dictionary for lookups by key.
For freshers: a clear interview answer
Say: "Both are ordered and allow duplicates. A list is mutable and has methods to add, remove and replace items. A tuple is immutable. A tuple can be a dictionary key only if all items inside it are hashable."
Interview note: If asked whether everything inside a tuple is immutable, use the tuple containing a list as your example. The slots stay fixed, but the list inside may change.
Practise with Python basics problems and Python interview questions. Try storing a cart, a coordinate, a group of unique skills and one student's marks. Choose a type for each and explain why. For more Python practice in data work, CodeBegun offers a data science course in Hyderabad and live online.
Frequently Asked Questions
Is a tuple faster than a list?
Can a tuple contain a list?
Why does a one-item tuple need a comma?
Can a list be a dictionary key?
Are Python sets and dictionaries ordered?
Want to Build Your Career in Data Science with AI?
Join CodeBegun and train with working industry engineers — Check the Data Science training details

