✦ Python Foundations Collections module

Concept 09 · Tuples

Keep values together.
Keep their positions fixed.

Tuples are useful for related values that form one whole, such as coordinates.

01 Learn02 Try03 Predict

A tuple is ordered but its items cannot be replaced.

Tuples are useful for related values that form one whole, such as coordinates.

coordinates = (45.26, 19.83)
latitude, longitude = coordinates
print(latitude)
print(longitude)

Tuple unpacking assigns each tuple value to a separate variable.

Try changing one value, then explain which part of the collection changed and why.

↳

Keep this in mind: Read the collection operation before predicting the result.

Try it
coordinates = (45.26, 19.83)

print(coordinates)
print(coordinates[0])

latitude, longitude = coordinates
print(latitude)
print(longitude)

Run the example, then change one value and observe the result.

Python Playground

Loading Python runtime…

Edit the example and run it in your browser.

tuples.pyPython
OutputWaiting for Python
The browser runtime is loading. You can still edit the example code.

Pyodide runs Python in a browser Web Worker. It is stopped and restarted if code keeps running. Browser execution is not a complete security boundary; do not enter secrets or rely on it for untrusted code isolation.

What will this program print?

Read each operation before choosing an answer.

colors = ("red", "blue", "green")
colors[1] = "yellow"
print(colors)
Choose the output
Sloby, the Python AI Tutor mascot

Your learning mentor

Ask Sloby about this concept

Describe what feels unclear and Sloby will guide your reasoning.

Hi! I'm Sloby. Let's explore this Python concept together.

What will this program print, and why? Explain unpacking and why changing x does not change point.

point = (10, 20)
x, y = point

x = 99

print(point)
print(x)
Python AI Tutor · Learn by understanding, not just by running code.