Python: What's the Difference Between Tuple and List?

By Xah Lee. Date: . Last updated: .

What is the difference between tuple and list?

The only difference, is that a tuple cannot be changed. You cannot change each element's value, and you cannot add or delete elements.

# -*- coding: utf-8 -*-
# python

# list and tuple can contain mixed datatypes, and arbitrarily nested.

my_list =  [3, "4", [11, "12"], ("a", 2), 5]
my_tuple = (3, "4", [11, "12"], ("a", 2), 5)

print my_list
print my_tuple
# -*- coding: utf-8 -*-
# python

# tuple cannot be changed

my_list =  [3, 4, 5]
my_tuple = (3, 4, 5)

my_list[0] =  9
my_tuple[0] = 9 # TypeError: 'tuple' object does not support item assignment

print my_list
print my_tuple

So, in practice, if you need a list but the elements or length never needs to change, then, use tuple.