Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
What do a and b show at the end? Say it before you run it.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Find out which names share one list.
b = a makes b a second name for the same list as a.c = a.copy() makes a new list for c.After b.append(4), the shared list is [1, 2, 3, 4], and it can be seen as a and as b.
After c.append(5), the separate list of c is [1, 2, 3, 5].
Check. a is b is True, and a is c is False.
Answer: [1, 2, 3, 4] for a, [1, 2, 3, 4] for b, and [1, 2, 3, 5] for c.
Log in to join the discussion.
Loading…