Python Lists
Keep ordered values together.
Python
scores = [82, 91, 76]
scores.append(95)
for score in scores:
print(score)Output
82 91 76 95
Explanation
A list stores an ordered collection. Indexes start at zero. Use append to add an item, and a for loop to visit each value.
Explore the dry run
Guided walkthroughReady
1
scores = [82, 91, 76]2
scores.append(95)3
for score in scores:4
print(score)Follow the example
Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.
View the complete dry-run table
| Step / line | What happens | State after step | Output so far |
|---|---|---|---|
| Create an ordered list of three scores. | scores = [82, 91, 76] | — | |
| Append 95 to the end of the same list. | scores = [82, 91, 76, 95] | — | |
| The loop visits each item in order. The print statement runs four times. | scores = [82, 91, 76, 95] | 82 91 76 95 |