×

python · level 2 · unit 2 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A is a sealed packet of values that belong together.

A tuple is like a list in round brackets, but sealed: once made, it cannot change. Use one for values that belong together and should stay put, like a city and its map position.

To a tuple, put one variable per value on the left of =. city, lat, lon = place puts each value in its own box, in order. Your two loop variables with .items() were unpacking tuples all along.

A function can return a tuple, so it can hand back two answers at once. Try to change a tuple, though, and you get a . A tuple has no .append() either, so trying it gives an .

def coldest_and_warmest(temps):
    return min(temps), max(temps)
low, high = coldest_and_warmest([12, 17, 9, 14])
print(f"Low {low}, high {high}")
place = ("London", 51.5, -0.12)
city, lat, lon = place
print(city, lat)

The commas make a tuple, so return min(temps), max(temps) hands back a tuple even without brackets.