How can I edit an existing list variable to add a new item?


#1

Question

For this exercise, how can I edit the existing list variable in the code to add new data items?

Answer

A list is an ordered collection of items. Lists are enclosed using the square brackets [] and each item is separated in the list using a comma. To edit an existing list, go the inside of the closing bracket ] and type a comma and then the new item to add to the list. To add multiple items, repeat the process by adding another comma and a new item but do not go beyond the closing square bracket of the list.

my_list = [1, 2, 3, 4]

# Edit the list in place. The new list will look like this:
my_list = [ 1, 2, 3, 4, 5]