Section 1 - Instruction

In our last session, we learned how to access individual items in a list using their index, like planets[1] to get "Venus".

What if we made a mistake or want to update an item in the list?

Engagement Message

Do you think we can change it?

Section 2 - Instruction

Yes, you can! Lists are mutable, meaning their contents can be changed after they are created.

You can replace an item at a specific index with a new value using the assignment operator =.

Engagement Message

How is this similar to assigning a value to a variable?

Section 3 - Instruction

The syntax is: list_name[index] = new_value.

If we have planets = ["Mercury", "Venus", "Earth"], we can change "Venus" to "Mars" like this: planets[1] = "Mars".

Engagement Message

What index would you use to change "Mercury"?

Section 4 - Instruction

After running planets[1] = "Mars", the planets list would now look like this: ["Mercury", "Mars", "Earth"].

The original value at that index ("Venus") is replaced by the new one ("Mars").

Engagement Message

What would planets[1] give you this change?

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal