This answer key contains 4 multiple-choice, 4 fill-in-the-blank, and 4 output-prediction questions for Python Lists, with the exact answer and a short explanation for every question.
The answers are shown in full, so use this page after making an attempt. The practice page is the better first pass.
What is the index of the first item in a list?
Answer: 0
Why: Python list indexes start at 0.
What does orders.append("tea") do?
Answer: Adds tea to the end of the list
Why: append changes the list in place and adds one item at the end.
How many items are in [10, 20, 30, 40][1:3]?
Answer: 2
Why: The slice starts at index 1 and stops before index 3, so it contains 20 and 30.
What is len([1, 2, 3])?
Answer: 3
Why: len counts the number of items in the list.
Complete the method that adds 4 to the end of the list.
items = [1, 2, 3]
items.____(4)Answer: append
Why: append adds one item to the end of a list.
Complete the index that reads the first item.
numbers = [10, 20, 30]
print(numbers[____])Answer: 0
Why: The first position in a Python list is index 0.
Complete the method that puts the numbers in ascending order.
numbers = [3, 1, 2]
numbers.____()Answer: sort
Why: sort() changes the list in place.
Complete the function that adds the numbers in the list.
print(____([4, 5, 6]))Answer: sum
Why: sum(list) returns the total of numeric values.
What does the program output?
print([10, 20, 30][1])Answer: 20
Why: Index 1 is the second item.
What appears on the screen?
items = [1, 2]
items.append(3)
print(items)Answer: [1, 2, 3]
Why: append adds 3 to the end of the list.
What is printed?
print([1, 2, 3, 4][1:3])Answer: [2, 3]
Why: The slice includes indexes 1 and 2, but not 3.
What is the output?
print(sum([4, 5, 6]))Answer: 15
Why: The sum of 4, 5, and 6 is 15.
Try the questions first
Open the practice page for Python Lists and answer the same 12 questions with instant feedback.