Tuple¶

Tuple is also a list, but immutable and hashable. A tuple containing the same data as a list takes up less space and works faster (explanation):

In [1]:
a = [2, 3, 'Boson', 'Higgs', 1.56e-22]
b = (2, 3, 'Boson', 'Higgs', 1.56e-22)

print(f'List: {a.__sizeof__()} bytes')
print(f'Tuple: {b.__sizeof__()} bytes')
List: 88 bytes
Tuple: 64 bytes

Python developers continuously work on optimizing internal storage structures. If you run the program shown above in Python 3.13, you'll see the result "List: 88 bytes, Tuple: 64 bytes", but the same program in Python 3.10 will give you the result "List: 104 bytes".

The tuple itself is immutable, but if there are mutable elements inside the tuple, such as lists or dictionaries, their values can be modified.