Lists: Exercises


1. Creating and Accessing Lists. In Python, lists are used to store collections of items. You can create a list by placing items inside square brackets [ ].

For example, you can define a list of numbers like this: numbers = [1, 2, 3, 4, 5]. To access items in a list, you can use indexing, starting with 0 for the first item (e.g. numbers[0].)

Start by defining the list of numbers from 6 to 8.

Select the list item at index value 1 and assign it to the variable item.


# Create a list of the numbers of 6 to 8. numbers = [6, 7, ___] # Access the item in the list with index value 1. item = ___ # Print the second item. print(item) # Create a list of the numbers of 6 to 8. numbers = [6, 7, ___] # Access the item in the list with index value 1. item = numbers[1] # Print the second item. print(item) test_object("numbers") test_object("item") success_msg("Correct! You created a list and then accessed the item at the right index value.")
To create a list, use square brackets [ ]. To access items, use indexing starting from 0.

Previous Exercise Next Exercise