← Back to Interactive Learning

Python Basics · Lesson 8

Tuples

Learn how Python tuples store ordered collections of values, access items, unpack values and understand immutability.

What is a Tuple?

A tuple is an ordered collection of values. Tuples are similar to lists, but their existing elements cannot be changed after creation.

student = ("Aman", 21, "Python")

print(student)

CHECK YOUR UNDERSTANDING

Which brackets are commonly used to create a tuple?

Tuple Indexing

numbers = (10, 20, 30, 40)

print(numbers[0])
print(numbers[2])

CHECK YOUR UNDERSTANDING

What does numbers[2] return?

Fill in the Blank

Access the first item: numbers[_____]

Negative Indexing

months = ("Jan", "Feb", "Mar", "Apr")

print(months[-1])

CHECK YOUR UNDERSTANDING

What does months[-1] return?

Tuples Are Immutable

Once a tuple is created, its existing elements cannot be changed directly.

numbers = (10, 20, 30)

numbers[1] = 50

CHECK YOUR UNDERSTANDING

What happens when you try to change numbers[1]?

len(), count() and index()

numbers = (10, 20, 10, 30, 10)

print(len(numbers))
print(numbers.count(10))
print(numbers.index(20))

CHECK YOUR UNDERSTANDING

What does numbers.count(10) return?

CHECK YOUR UNDERSTANDING

What does numbers.index(20) return?

Fill in the Blank

Find the number of tuple items: total = _____(numbers)

Tuple Unpacking

student = ("Aman", 21, "Python")

name, age, course = student

print(name)
print(age)
print(course)

CHECK YOUR UNDERSTANDING

What value will be stored in age?

Fill in the Blank

Complete: name, age, course _____ student

Tuple vs List

FeatureListTuple
Syntax[ ]( )
MutableYesNo
OrderedYesYes

CHECK YOUR UNDERSTANDING

Which structure should you use when existing items need to be changed?

Final Challenge

Build a Sales Record

Create a tuple containing a product, price and quantity. Unpack the values and calculate revenue.

sale = ("Laptop", 55000, 2)

product, price, quantity = sale

revenue = price * quantity

print(product)
print(revenue)

Expected revenue: ₹110000

Lesson recap

  • ✓ Tuples are ordered.
  • ✓ Tuple indexing starts at 0.
  • ✓ -1 refers to the last item.
  • ✓ Tuples are immutable.
  • ✓ len() counts items.
  • ✓ count() counts occurrences.
  • ✓ index() finds a position.
  • ✓ Tuple unpacking assigns values to variables.