Python: Exercises


1. Defining lists. In Python, a list is an object that holds a collection of items.

A list is defined by enclosing a set of set of comma-separated values inside of a pair of brackets. This is a list of strings, where a string is defined by enclosing text in quotation marks.

$$\text{a_list} = \text{[``this", ``is", ``a", ``list"]}$$

A list can be empty, can contain multiple types (e.g. numbers and strings), and can contain multiple lists.

$$\text{a_list_of_lists} = [[0,1,2],[3,4,5]]$$

Define lists that contain the following items.

1. The integers between 1 and 5.

2. The sequence of letters a, b, c, d.


# Define a list that contains the integers between 1 and 5. integer_list = [1, ___, ___, ___, ___] # Define a list of alphabet characters between a and d. string_list = ["a", ___, ___, ___] # Define a list that contains the integers between 1 and 5. integer_list = [1, 2, 3, 4, 5] # Define a list of alphabet characters between a and d. string_list = ["a", "b", "c", "d"] test_object("integer_list") test_object("string_list") success_msg("Excellent work.")
Remember to enclose strings within quotation marks.

Previous Exercise Next Exercise