Menu
Coddy logo textTech

Tuple

Part of the Fundamentals section of Coddy's Python journey — lesson 59 of 77.

A tuple is an immutable (read-only) ordered collection of elements. Unlike lists, once created, tuples cannot be modified.

Create a tuple with parentheses:

fruits = ("apple", "banana", "cherry")

You can also create a tuple without parentheses:

colors = "red", "green", "blue"

Access tuple elements using indexing (just like lists):

first_fruit = fruits[0]  # "apple"

Remember, tuples are immutable, so you cannot modify elements:

# This will cause an error
# fruits[0] = "orange"

A tuple with a single element needs a trailing comma:

single_item = ("apple",)  # This is a tuple
not_a_tuple = ("apple")   # This is a string

Cheat sheet

Tuples in Python:

  • Immutable (read-only) data structure
  • Created using parentheses ()
  • Access elements using indexing, including negative indexing
# Creating a tuple
coordinates = (4, 5)

# Accessing elements
x = coordinates[0]  # 4
y = coordinates[1]  # 5

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals