Skip to the content

Choosing the structure

Python · Unit 8: Tuples and sets

Each structure is for something different. List: several values in order, that are going to change.

Tuple: a few pieces of data that belong together and don't change.

line = ["Amy", "Leo"]
line.append("Sam")
bday = (14, "Feb")
print(line, bday[1])

Prints

['Amy', 'Leo', 'Sam'] Feb

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Multiple choice

    You're going to store the line at the bank. People arrive, people leave and the order matters. What do you use?

  2. 2. Multiple choice

    You want to store your date of birth, for example May 5, 2005 as 5, 5, 2005. What do you use?

  3. 3. Multiple choice

    You're keeping track of each player's goals on the team and updating them. What do you use?

  4. 4. Find the bug

    This program should count how many different countries Emma visited. Which line has the bug?

  5. 5. Predict the output

    What does this code print?

  6. 6. Multiple choice

    Which of these values can't be a dictionary key?

  7. 7. Find the bug

    This program should save Amy in row 3, seat 5. Which line has the bug?

  8. 8. Predict the output

    What does this code print?

  9. 9. Complete the code

    Complete it to put an X in row 1, column 2 of the board.

  10. 10. Predict the output

    Rolls of two dice are being counted. What does it print?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →