Syncing account progress…

Back

Beginner · 10 min

Your first list

Keep several values in a list and access them by position.

Group related values

A list uses square brackets with commas between items. Use len() to count its items. Lists keep items in order.

items = ["bread", "milk", "eggs"]
print(len(items))

Output

3

Read an item by index

List positions start at zero. Index 0 selects the first item and -1 selects the last. An index outside the list raises an error.

items = ["bread", "milk", "eggs"]
print(items[0])
print(items[-1])

Output

bread
eggs

Your first list

  1. Number the list positions starting at zero.
  2. Find the first and last items.

Try it yourself

Code runs on this device. When you are signed in, drafts sync to your account.

Read a shopping list

Use the supplied list. Store its first item in first and its length in count, then display first and count on separate lines.

Practice