What is the difference between a list and a tuple in Python?

The main difference is that a list is mutable (you can change it) and a tuple is immutable (you cannot change it after creating it).

PointListTuple
Brackets[ ]( )
Can change itemsYesNo
Speed and memoryA little slower, uses more memoryA little faster, uses less memory
MethodsMany, like append() and remove()Only count() and index()
Use as dictionary keyNoYes, if it holds only immutable items
my_list = [1, 2, 3]
my_list[0] = 10
print(my_list)

my_tuple = (1, 2, 3)
my_tuple[0] = 10

Output:

Tutorials Class - Output Window

[10, 2, 3]
TypeError: 'tuple' object does not support item assignment

Use a list when the data will change, and a tuple when it should stay fixed. Read more about lists and tuples.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.