Sharpen your Python list skills with fill-in-the-blank exercises. Practice indexing, slicing, list methods, and more to reinforce your understanding of core list operations in Python.
Topic: lists
any_valid_variable_name
Lists are created using square brackets, and can be assigned to any valid variable name.
-1
Negative indices count from the end (-1 is last element, -2 is second last, etc.)
append
append() adds a single element to the end of the list
1:6:2
The slice start:stop:step gets elements from start to stop-1, stepping by step
reverse
The reverse() method reverses the list elements in their place
index
index() returns the position of the first matching element
original_list
Slicing with [:] creates a new copy of the entire list
clear
clear() empties the list while maintaining the list object
colors = ['red', 'green', 'blue']
print(colors[______])
1
List indices start at 0, so 'green' is at position 1
numbers = [1, 2, 3, 4, 5]
subset = numbers[______] # Gets [2, 3, 4]
1:4
Slices are start-inclusive and end-exclusive
data = [10, 20, 30]
data.______(40)
print(data) # Outputs [10, 20, 30, 40]
append
append() adds an element to the end of the list