So far, our lists don't change over time. If we create a list with 3 elements, it will always have the same 3 elements. But this doesn't need to be this way.
We can add elements to a list during the program, using the function append
, which lives inside lists. For example, try the following program:
a = [2, 4, 8]
a.append(16)
print(a)
We can create long lists using loops. For example, type this program:
a = []
count = 0
while count < 100:
a.append(count)
count += 2
print(a)
Let's improve on the program from the last lesson. If you don't have it at hand, type it from scratch. Then make the following changes:
actor1
and actor2
.actor_list
be an empty list.actor_list
, each one in a slightly different position.Run the program. How did that go? If all is correct, there should be 20 images moving in the screen.