Immutable Python Tuples

In [151]:
# Create a tuple of countries in America
america = ('Canada', 'Mexico', 'United States')
In [152]:
# Print countries in America
print(america)
('Canada', 'Mexico', 'United States')
In [153]:
# Access the items of a tuple with [index]
print(america[0])
print(america[1])
print(america[2])
Canada
Mexico
United States
In [154]:
# How many countries in America? (length of America)
print('There are', len(america), 'countries in', america)
There are 3 countries in ('Canada', 'Mexico', 'United States')
In [155]:
# Check if Canada is in America
'Canada' in america
Out[155]:
True

Once a tuple is created, we cannot add items to or remove items from it. Tuples are immutable (unchangable)