Skip to content

Tuple

A tuple is a sequence of values in parentheses, like (16, 5). It works like a Python list that stays the same after it's made.

How to do it: create a tuple and unpack its values in Python

Select any words here to ask your Maestro about them.

How to do it

Create a tuple and unpack its values in Python

Steps for Python

Python
point = (40.71, -74.01)  # latitude, longitudelatitude, longitude = pointprint(latitude, longitude, len(point))def low_and_high(numbers):    return min(numbers), max(numbers)  # returns a tuplelow, high = low_and_high([42, 35, 58, 27])print(low, high)
Output
40.71 -74.01 227 58

Unpacking assigns each value to its variable in order; that's how a function returns two values at once. A tuple can't be changed: point[0] = 0 raises TypeError.

How to tell it worked. len(point) gives 2 and each variable holds its value. If you see ValueError: too many values to unpack, you have fewer variables than values.

Ask an AI assistant

For your own sheet, in ChatGPT, Claude or Copilot: copy the prompt and fill in the brackets.

Using an example from my data describe it, explain when to use a tuple in Python instead of a list, and how to unpack it.
Prompt

Write yours in the highlighted part. Anything left in brackets reaches your agent as is.

pandas answers df.shape with a tuple: (16, 5) means 16 rows and 5 columns. You read its values by position, from 0, as you would in a list:

Python
rows, columns = df.shapedf.shape[0]   # 16

A cell that ends with two values and a comma between them, like alt.__version__, pd.__version__, shows a tuple too.

Ask your Maestro about Tuple

It answers from the free course page closest to this word, the way it answers while you study.

Example

You: What does "Tuple" mean, in plain words?

Your Maestro: I'll explain it with a case of yours: it sticks better than a definition. Want to see what df.shape says about your table?

Asking about: Answers from the page "How do you know it's right?"

Only this browser keeps what you ask here. How it works

In Maestro's courses

Learn more

The whole glossary