Editor

Predict the Output: List Aliasing

Intermediate · Predict the output · from Python Lists: Create, Access, Modify, and Loop Through Lists

From the lesson: Python Lists: Create, Access, Modify, and Loop Through Lists

Think about your favorite music playlist. It has a bunch of songs stored in a specific order. You can add new songs, remove old ones, rearrange them, or skip to song number five.

Read the lesson

Read this code carefully and predict what it will print. Think about what happens when two variables point to the same list.

Type the exact output (each value on a new line if there are multiple prints).

a = [1, 2, 3]
b = a
b.append(4)
print(a)
print(b)

More Lists exercises

All Python exercises · 50 practice problems · Data Structures quiz