← back to unit
Easy
# basics variables
Accessing List and Dictionary Data
You can grab a single value out of a list using its index — its position, counting from 0:
fruits = ["apple", "banana", "cherry"]
print(fruits[0])
print(fruits[2])
prints:
apple
cherry
For a dictionary, you grab a value using its key instead of a position:
ages = {"Sam": 10, "Zoe": 12}
print(ages["Zoe"])
prints: 12
Your turn: a list colors and a dictionary scores are given. Print colors[1] (the second color), then print scores["Sam"] (Sam's score).
💡 need a hint?
pyb-var-access-list-dict.py🔒 given lines are locked — write your code in between
loading...