← All lessons

List indexes

Sign in · Sign up

Lesson 5.1

Every item of a list has a number — an index, counted from zero:

games = ["Minecraft", "Roblox", "Brawl Stars"]

print(games[0])    # Minecraft
print(games[-1])   # Brawl Stars — the last one

-1 is a short way to take the last item. A number beyond the list is an error: with three items there is no index 3.

The list items is set by the check. Print, in order:

  1. the first item;
  2. the last item.
Hint

Indexes start at zero: the first is [0], the second is [1].

[-1] counts from the end: it is the last item.