python · level 1 · unit 6 · lesson 1
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
A keeps many values together in one box.
A shopping list does not need a new piece of paper for every thing you buy. One list holds them all, in order. A Python list does the same, so one variable can hold lots of values.
Write a list with square brackets [ ] and put a comma between the values. Each value in the list is called an . len() counts the items, not the letters.
Printing a list shows the brackets and commas too. Python shows text items with single quotes, like 'milk'. That is fine: single and double quotes mean the same thing.
shopping = ["bread", "milk", "eggs"]
print(shopping)
print(len(shopping)) Lists can hold numbers too, like scores = [7, 10, 4].
guess first
Items or letters? What will len count?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
pets = ["cat", "dog", "goldfish"]
print(len(pets))
your turn
Your turn. Make a list of your favourite things.
Type three favourite things between the quotes: foods, films, animals, anything you love. Then press run.
fix it
Three snacks went in, but only two came out. Can you fix it?
- Look at the printed list. Where did applepopcorn come from?
- Something is missing between "apple" and "popcorn", so Python glued them into one item.
- Add a comma after "apple", then run it again.
nailed it
you packed lots of things into one list. :D
- A list holds many items inside square brackets.
- Put a comma between every item.
len()on a list counts its items.
new words in your collection
- list
- item
This lesson isn’t saved. A free account remembers every lesson you finish.