Pick a Spot ๐ข
Want just one thing out of a list? Use its position in square brackets.
Here's the weird-but-true part: positions start at 0, not 1!
pets = ["cat", "dog", "fox"]
print(pets[0]) # โ cat (the FIRST one)
print(pets[1]) # โ dog
print(pets[2]) # โ fox
So a list of 3 things has positions 0, 1, and 2. Programmers count from zero!
To find out how many things are in a list, use len():
print(len(pets)) # โ 3
Bonus trick: pets[-1] means "the last one", no counting required. ๐
Your mission
- Make a list called
top5with exactly 5 favorite things (songs, movies, anything) - Print the first one using
[0] - Print the last one using
[4](or[-1]) - Print how many things are in the list using
len()
Your code
Press โถ Run to see what your code does!